将JSON数据绑定到sap.m.Table中的sap.m.Select

时间:2014-12-14 18:42:13

标签: sap sapui5

我是SAPUI5开发的新手,我陷入了这样的境地:我已经嵌套了从服务器返回的JSON数据,我希望将数据绑定到表中的选择列表。但是数据并没有绑定到select。

Screenshot

返回的JSON数据是这样的:

{"KEY":[
  {
  "SYSTEM_ID":"BHD",
  "TCODE":"SM66",
  "SHIFT_ID":"A",
  "SHIFT_DATE":"20141121",
  "USER_ID":"NISHANT_T",
  "PARA_VAL":"3",
  "INFO_CHARNUM":"TEST",
  "INFO_UNIT":"",
  "INFO_DATE":"20141121",
  "INFO_TIME":"142345",
  "ATTACH_ID":[
  {
  "ID":"A"
  },
  {
  "ID":"B"
  },
  {
  "ID":"C"
  }
  ],
  "NOTES":"DOC",
  "MESSAGE":""
  }]}

我想绑定ATTACH_ID数据以进行选择。 视图文件的代码是:

items: {
         path: "/KEY",
         template: new sap.m.ColumnListItem({
          type:  sap.m.ListType.Active,
           cells: [

                   new sap.m.Label({
                     text : "{SYSTEM_ID}"  //
                 }),

                 new sap.m.Label({
                     text : "{SHIFT_ID}"  //
                 }),

                 new sap.m.Label({
                     text : "{SHIFT_DATE}"  //
                 }),
                 new sap.m.Select({
                  path:"{/ATTACH_ID}",
                  items: [
                          new sap.ui.core.Item({
                          key:"{ID}",
                          value:"{ID}"
                          }) 
                         ]
                 }),




         ]

         })
    }

不知道该怎么做。数据正确绑定到表但不选择。请建议正确的方法。 感谢。

1 个答案:

答案 0 :(得分:1)

我通过测试完成了我的自我

onInit: function() {
     debugger;

    var data = [
                {name:"sankar",  name2:"kumar",  age:"20",value:false},
                {name:"sathis",  name2:"kumar",  age:"22",value:true},
                {name:"arun",  name2:"kumar",  age:"24",value:true},
                {name:"siva",  name2:"kumar",  age:"26",value:false}];
    var gender = [{gen:" "},
                  {gen:"Male"},
                  {gen:"Female"}];  //select//
    var oModel = new sap.ui.model.json.JSONModel();
         oModel.setData({
            sex     : gender,    
            rows    : data
        });   //select:sex//
            sap.ui.getCore().setModel(oModel);
             var oItemSelectTemplate = new sap.ui.core.Item({  
                    key : "{gen}",  
                    text : "{gen}"  
                });  //select-items//
    var opan =  this.getView().byId("panel");
    var otab = new sap.m.Table("items", {
            inset: true,
            columns : [
                new sap.m.Column({
                    styleClass : "name",
                    hAlign : "Left",
                    header : new sap.m.Label({
                        text : "name"
                    })     }),
                new sap.m.Column({
                    styleClass : "name",
                    hAlign : "Left",
                    header : new sap.m.Label({
                        text : "name2"
                    }) }),
                    new sap.m.Column({
                        styleClass : "gender",
                        hAlign : "Left",
                        header : new sap.m.Label({
                            text : "gender"
                        })}),
                    new sap.m.Column({
                        styleClass : "name",
                        hAlign : "Left",
                        header : new sap.m.Label({
                            text : "status"
                        })

                })
            ],

        });

//  otab.setBackgroundDesign("Transparent");

    var template = new sap.m.ColumnListItem({
        type : "Navigation",
        cells : [
            new sap.m.Input({
                value : "{name}"
            }),
            new sap.m.Input({
                value : "{name2}"
            }),
            new sap.m.Select("select",{


            }),   //select//
            new sap.m.CheckBox({
                selected : "{value}"
            })

        ]
    });
 sap.ui.getCore().byId("select").bindAggregation("items","/sex",oItemSelectTemplate);  //select-binding//


otab.bindItems("/rows", template);
 opan.addContent(otab);