SAPUI5将模型从核心绑定到列表

时间:2014-07-14 15:48:09

标签: javascript model-view-controller sap sapui5

我的应用程序中有两个模型,我绑定到sap.ui.core。 以下代码来自我的主视图。这是一个拆分应用程序。

var checks = {
    items: [
    {
        checklist: "ContainerCheck",
        title:"Scan RFID container",
    }
    // etc...
]}
;

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

在另一个视图中,我想将数据绑定到母版页

var oItemTemplate = new sap.m.ActionListItem({
    title : "{title}",
    icon : "sap-icon://activity-2",
    activeIcon: "sap-icon://activity-2",
    type : sap.m.ListType.Active,
});

this.oList = new sap.m.List({
    itemPress: [oController.onListSelect, oController]
});

this.oList.bindItems("checks>/items",oItemTemplate);

但是我没有在列表中看到任何数据。我很确定sPath是正确的checks>/items。是否无法使用此sPath,因为模型绑定到sap.ui.core。还是我错过了别的什么?

3 个答案:

答案 0 :(得分:2)

我很确定你必须在propertyBinding前加上模型名称:

var oItemTemplate = new sap.m.ActionListItem({
    title : "{checks>title}",
    ...
});

这应该有效。

答案 1 :(得分:0)

试试这个this.oList.bindItems("{checks>/items}", oItemTemplete);代替this.oList.bindItems("checks>/items",oItemTemplate);

答案 2 :(得分:0)

我偶然发现了同样的问题,过了一会儿我找到了this comment

  

控件只能绑定到一个模型,因此如果您有一个带有指定模型的容器控件,则此容器中包含的所有控件只能看到容器的本地模型,并且不再能够绑定到全局模型

我认为这是您代码中的问题。至少那是我的那个: - )

相关问题