Anonymoose
Anonymoose

Reputation: 2471

SAPUI5 bind model from core to list

I have 2 models in my application that I bind to 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. Is it not possible to use this sPath because the model is bind to sap.ui.core. Or am I missing something else?

Upvotes: 1

Views: 1752

Answers (3)

bgerth
bgerth

Reputation: 1286

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

Upvotes: 0

masch
masch

Reputation: 594

I'm pretty sure you have to prefix the propertyBinding with the models name:

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

This should work.

Upvotes: 2

Saddamhussain
Saddamhussain

Reputation: 870

Try this this.oList.bindItems("{checks>/items}", oItemTemplete); instead of this.oList.bindItems("checks>/items",oItemTemplate);

Upvotes: 0

Related Questions