Search code examples
odatasapui5

Load entity without binding it to a view


In a controller (Detail.controller.js) I want to access an OData-Entity that has not yet been bound to a control.

If the entry 0001 of my BananaSet is bound to the view, I can access the raw data via

this.getView().getModel().getProperty("/BananaSet('0001')");

but the following will return undefined (unless it was displayed recently).

this.getView().getModel().getProperty("/BananaSet('0002')");
this.getView().getModel().getProperty("/MetaDataSet('0001')");

Is there a way to access data or entities of an OData model, that have not yet been bound?


Solution

  • To explicitly trigger a request to an entity you may use the read function of the oData model.

    Here is the official documentation:
    https://openui5.hana.ondemand.com/docs/api/symbols/sap.ui.model.odata.v2.ODataModel.html#read

    this.getView().getModel().read("/BananaSet('001')", {
        success: function (oData) {
            // do something with the Banana data
        }
    })