4

我创建了一个响应式 sap.m.table。但我无法从数据对象加载值。我想加载对象的“子变量”数组。请帮助

 summaryDetailData={"subvariants":[{"currentValue":"","Article":"1234567","question":"Carpet Installation type"},{"currentValue":"","question":"CarpetQuantity"},{"currentValue":"","Article":"1234568","question":"Underpad type"},{"currentValue":"","question":"UnderpadQuantity"},{"currentValue":false,"Article":"1234568","question":"Rapid Install"}]}



  var oTable = new sap.m.Table("idRandomDataTable", {
    headerToolbar: new sap.m.Toolbar({
    content: [
    new sap.m.Label({text: "Summary Data"}),
    new sap.m.ToolbarSpacer({}),
    new sap.m.Button("idPersonalizationButton", {
    icon: "sap-icon://person-placeholder"
    })]}),
     columns: summaryDetailData.cols.map(function (colname) {
        return new sap.m.Column({ header: new sap.m.Label({ text: colname })})
            })      
    });

    oTable.setModel(new sap.ui.model.json.JSONModel(summaryDetailData));
    oTable.bindAggregation("subvariants", "/subvariants", new sap.m.ColumnListItem({
        cells: oData.cols.map(function (colname) {
            return new sap.m.Label({ text: "{" + colname.toLowerCase() + "}" })
            })
        }));
4

1 回答 1

8

将模型绑定到表的方式并不完全正确。您必须使用bindItems将表行(项目)动态绑定到模型。columns聚合用于定义表的列布局,而聚合items负责表记录。

在您的情况下,我将在控件定义中创建列,并使用您自己的模板将项目绑定到模型。

这应该符合您的预期(已测试):

var oTable = new sap.m.Table("idRandomDataTable", {
        headerToolbar : new sap.m.Toolbar({
            content : [ new sap.m.Label({
                text : "Summary Data"
            }), new sap.m.ToolbarSpacer({}), new sap.m.Button("idPersonalizationButton", {
                icon : "sap-icon://person-placeholder"
            }) ]
        }),
        columns : [ new sap.m.Column({
            width : "2em",
            header : new sap.m.Label({
                text : "Current Value"
            })
        }), new sap.m.Column({
            width : "2em",
            header : new sap.m.Label({
                text : "Article"
            })
        }), new sap.m.Column({
            width : "2em",
            header : new sap.m.Label({
                text : "Question"
            })
        }) ]
    });

    oTable.bindItems("/subvariants", new sap.m.ColumnListItem({
        cells : [ new sap.m.Text({
            text : "{currentValue}"
        }), new sap.m.Text({
            text : "{Article}"
        }), new sap.m.Text({
            text : "{question}",
        }), ]
    }));

    oTable.setModel(new sap.ui.model.json.JSONModel(summaryDetailData));

希望这可以帮助你!

于 2014-01-10T09:59:47.240 回答