如何基于json属性将项绑定到控制器

时间:2017-01-03 16:36:53

标签: javascript json model-view-controller sapui5

以下是我的json对象。我想用密钥为对象创建一个表:“month”

 Object
   oData
   details:
   Array[4]
   0:Object
   1:Object
   2:Object
    editable:false
    key:"year"
    removeable:false
    value:"2000"
   3:Object
    editable:false
    key:"time"
    removeable:false
    value:"Day: TRUE, Night:False"
   4:Object
    editable:false
    key:"month"
    removeable:false
    value:"August"

视图是

 var viewModel = that.getView().getModel();
 var viewModelData = viewModel.getData();
 var systemModelData = system.getModelData();
 viewModel.setData($.extend(viewModelData, systemModelData));

//控制研究

createContent : function(oController) {
     return new sap.m.Table({
       columns: [
                new sap.m.Column({
                    header: new sap.m.Text({
                        text: 'key',
                    })
                }),
       items: {
                path: '/details',
                template: new sap.m.ColumnListItem({
                    cells: [
                        new sap.m.Text({
                            text: '{key}',
                        }),

我应该更改绑定路径以获得结果。或者更改应该在模型中。

1 个答案:

答案 0 :(得分:1)

您可以使用filter仅在绑定数组中显示对象:

createContent : function(oController) {
     return new sap.m.Table({
       columns: [
                new sap.m.Column({
                    header: new sap.m.Text({
                        text: 'key',
                    })
                }),
                new sap.m.Column({
                    header: new sap.m.Text({
                        text: 'value',
                    })
                }),
       items: {
                path: '/details',
                filters: [ new sap.ui.model.Filter("key","EQ","month") ], //only display months
                template: new sap.m.ColumnListItem({
                    cells: [
                        new sap.m.Text({
                            text: '{key}',
                        }),
                        new sap.m.Text({
                            text: '{value}',
                        }),