5
votes

after reading Multimodel Support I tried to implement it. When using a named model the binding happens but the data is not displayed.

// Controller

sap.ui.controller("view.apps.Apps", {

    onInit : function () {
        var oAppsModel = new sap.ui.model.json.JSONModel("model/apps.json");
        this.getView().setModel(oAppsModel, "apps");
    }
});

// View

sap.ui.jsview("view.apps.Apps", {

    getControllerName: function() {
        return "view.apps.Apps";
    },

    createContent: function(oController) {

        var oInboxList = new sap.m.List({
            inset: true,
            id: "appsList",
            headerText: "Apps"
        });

        oInboxList.bindItems("apps>/items", function(sID, oContext) {
            return new sap.m.StandardListItem({
                title: '{name}',
                description: '{name}'
            })
        });

        var oPage = new sap.m.Page({
            title: "Apps",
            content: [oInboxList]
        });

        return oPage;
    }
 });

// apps.json

{
    "items": [{
        "name": "ABC",
        "view": ""
    }, {
        "name": "DEF",
        "view": ""
    }]
}

This View produces two empty ListItems. When I change the model to an unnamed model and I update the BindPath to /items the List gets properly populated and the values are displayed. Any ideas on whats wrong with my coding? I'd really like to use the named models.

1

1 Answers

14
votes

OK, just reread the documentation. It is necessary to prefix ALL bindings with the name of the named model when using a named model for binding.

oInboxList.bindItems("apps>/items", function(sID, oContext) {
        return new sap.m.StandardListItem({
            title: '{apps>name}',
            description: '{apps>name}'
          })
    });