从JSView动态读取值

时间:2016-01-26 11:34:59

标签: javascript sapui5

我在JSView的表中显示了一些值,我想读取特定行的值并将其显示在表的同一列中。

例如:

在第一行

  • Field1的值为"My App"
  • Field2的值为"Test"

在Field3中,我希望This is my App Test

在第二行

  • Field1的值为"My App"
  • Field2的值为"Test2"

在Field3中,我希望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;

    }
});

Field1和Field2来自OData服务,它运行正常。

1 个答案:

答案 0 :(得分:0)

通过动态设置id,您可以轻松生成前两个字段内容。

对此jsFiddle

有一个方法