SAPUI5多模型绑定

时间:2014-11-27 09:04:01

标签: model-binding sapui5

我遇到多模式绑定问题。

在控制器的init函数中,我在ui.core中设置了JSON模型

var oModel = new sap.ui.model.json.JSONModel(data1);
sap.ui.getCore().setModel(oModel, "model1");

在View中我有一个ColumnListItem模板,我将它绑定在一个表

    var template = new sap.m.ColumnListItem({
          id: "first_template",
          type: "Navigation",
          type : sap.m.ListType.Active,
          visible: true,
          selected: true,
          cells: [ new sap.m.Label({
                    text: "{name}"
                    })
          ],
          press: [oController.pressListMethod]


  });

   oTable.bindItems("model1>/events", template, null, null);
   oPage.addContent(oTable);

使用简单的模型,它可以工作,但在Multimodel表中只获取项目数,但不获取模型的属性。有解决方案吗

1 个答案:

答案 0 :(得分:2)

您还需要在模板中使用模型名称:

var template = new sap.m.ColumnListItem({
  id: "first_template",
  type: "Navigation",
  type : sap.m.ListType.Active,
  visible: true,
  selected: true,
  cells: [ 
    new sap.m.Label({
      text: "{model1>name}" // No leading "/" here since the binding is relative to the aggregation binding below
    })
  ],
  press: oController.pressListMethod
});

oTable.bindItems("model1>/events", template);
oPage.addContent(oTable);