How to bind items to a controller based on json pr

2019-06-10 00:49发布

问题:

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:

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