2016-01-26 31 views
-1

我在JSView的表中顯示了一些值,我想讀取特定行的值並將其顯示在表格的同一列中。從JSView動態讀取的值

例如:

在第一行

  • 字段1的值是"My App"
  • 字段2的值爲​​

在字段3我想有This is my App Test

在第二行

  • 字段1具有價值"My App"
  • 字段2的值爲"Test2"

在字段3我想有This is my App Test2

將動態讀取值並將其放入Field3中的最佳方法是什麼?

這裏是我的視圖的定義:

sap.ui.jsview("views.TEST", { 

    getControllerName: function() { 
     return null; 
    }, 

    createContent: function(oController) { 
     var oLayout = new sap.ui.commons.layout.MatrixLayout({ 
      width: "100%" 
     }); 

     var oModel = new sap.ui.model.json.JSONModel(); 

     oModel.loadData("My Data"); 


     var oControl; 
     this.oSHTable = new sap.ui.table.Table("soTable1", { 
      visibleRowCount: 10, 
     }); 


     oControl = new sap.ui.commons.TextView().bindProperty("text", "Field1"); 
     this.oSHTable.addColumn(new sap.ui.table.Column({ 
      label: new sap.ui.commons.Label({ 
       text: "Col1" 
      }), 
      template: oControl, 
      sortProperty: "Field1", 
      filterProperty: "Field1", 
      filterOperator: sap.ui.model.FilterOperator.EQ, 
      flexible: true 
     })); 

     oControl = new sap.ui.commons.TextView().bindProperty("text", "Field2"); 
     this.oSHTable.addColumn(new sap.ui.table.Column({ 
      label: new sap.ui.commons.Label({ 
       text: "Col2" 
      }), 
      template: oControl, 
      sortProperty: "Field2", 
      filterProperty: "Field2", 
      filterOperator: sap.ui.model.FilterOperator.EQ, 
      flexible: true 
     })); 


     oControl = new sap.ui.commons.TextView().bindProperty("text", "Field3"); 
     this.oSHTable.addColumn(new sap.ui.table.Column({ 
      label: new sap.ui.commons.Label({ 
       text: "Col3" 
      }), 
      template: oControl, 
      sortProperty: "Field3", 
      filterProperty: "Field3", 
      filterOperator: sap.ui.model.FilterOperator.EQ, 
      flexible: true 
     })); 

     this.oSHTable.setModel(oModel); 
     this.oSHTable.bindRows("/"); 

     this.oSHTable.setTitle("List"); 
     oLayout.createRow(this.oSHTable); 

     return oLayout; 

    } 
}); 

字段1和Field2從OData的服務來和它的正常工作。

+0

代碼請!告訴我們你做了什麼! –

+0

完成。讓我知道是否需要更多信息。 –

+0

當你爲Field3初始化TextView時,你可以嘗試以下方法:'oControl = new sap.ui.commons.TextView(text:「This is {Field1} {Field2}」);'。在你的index.html中添加以下內容:'data-sap-ui-bindingSyntax =「complex」' – Marc

回答

0

您可以通過動態設置id輕鬆地生成前兩個字段的第三個字段內容。

對此有一個lovers jsFiddle

+0

感謝您的答案,但我想讀取字段1和2的值,而不只是計數器。 –

+0

這是我的代碼。 –