简体   繁体   English

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

[英]SAPUI5 bind model from core to list

I have 2 models in my application that I bind to sap.ui.core.我的应用程序中有 2 个绑定到 sap.ui.core 的模型。 The following code is from my main view.以下代码来自我的主要观点。 Which is a split-app.这是一个拆分应用程序。

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");

In another view I want to bind data to the masterpage在另一个视图中,我想将数据绑定到母版页

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);

However I'm not seeing any data in the list.但是我没有在列表中看到任何数据。 I'm quite sure the sPath is correct checks>/items .我很确定 sPath 是正确的checks>/items Is it not possible to use this sPath because the model is bind to sap.ui.core .是否无法使用此 sPath 因为模型绑定到sap.ui.core Or am I missing something else?还是我错过了其他东西?

I'm pretty sure you have to prefix the propertyBinding with the models name:我很确定您必须在 propertyBinding 前面加上模型名称:

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

This should work.这应该有效。

Try this this.oList.bindItems("{checks>/items}", oItemTemplete);试试这个this.oList.bindItems("{checks>/items}", oItemTemplete); instead of this.oList.bindItems("checks>/items",oItemTemplate);而不是this.oList.bindItems("checks>/items",oItemTemplate);

I stumbled about the same problem and after a while I found this comment :我偶然发现了同样的问题,过了一会儿我发现了这个评论

A control can only bind to one model, so if you have a container control with an assigned model, all controls contained in this container can only see the local model of the container and are no longer able to bind to the global model.一个控件只能绑定一个模型,所以如果你有一个指定了模型的容器控件,这个容器中包含的所有控件只能看到容器的本地模型,不能再绑定到全局模型。

I assume that is the problem in your code.我认为这是您的代码中的问题。 At least that's the one in mine :-)至少这是我的:-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM