Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OPENUI5: Named Model Aggregate Binding Data is not showing

Tags:

sapui5

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.

like image 858
Kai Avatar asked Aug 20 '14 09:08

Kai


1 Answers

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}'
          })
    });
like image 164
Kai Avatar answered Oct 15 '22 03:10

Kai