How to bind items to a controller based on json pr

2019-06-10 00:39发布

The following is my json object. I want to make a table for the object with the key:"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"

The view is

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

//controll

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}',
                        }),

Should I change the binding path to get the results. Or the change should be in the model.

1条回答
孤傲高冷的网名
2楼-- · 2019-06-10 00:55

You can use a filter to display only the month objects in the bound array:

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}',
                        }),
查看更多
登录 后发表回答