Detail page of split app without model

帅比萌擦擦* 提交于 2019-12-12 05:49:14

问题


In my split app the detail view does not bind any model.

In the component.js I instantiate a named model like this:

// creation and setup of the oData model
var oConfig = {
    metadataUrlParams: {},
    json: true,
    defaultBindingMode : "TwoWay",
    defaultCountMode : "Inline",
    useBatch : false
}

// ### tab-employee ###
var oModelEmpl = new sap.ui.model.odata.v2.ODataModel("/sap/opu/odata/sap/EMP_SRV"), oConfig);

oModelEmpl.attachMetadataFailed(function() {
     this.getEventBus().publish("Component", "MetadataFailedEMPL");
}, this);

this.setModel(oModelEmpl, "EMPL");

The method onSelect in der master-view controller is fired by clicking on an listitem.

onSelect: function(oEvent) {                          
    this.showDetail(oEvent.getParameter("listItem") || oEvent.getSource());
     }

This will call the method showDetail

showDetail: function(oItem) { 
    var bReplace = jQuery.device.is.phone ? false : true;
    this.getRouter().navTo("detail", {
        from: "master",
        entity: oItem.getBindingContext('EMPL').getPath().substr(1),
    }, bReplace); 
},

In the controller of the detail-view I've these two methods for updating the binding. onRouteMatched calls bindView, where I get the error-message TypeError: oView.getModel(...) is undefined.

onRouteMatched: function(oEvent) {
    var oParameters = oEvent.getParameters();

    jQuery.when(this.oInitialLoadFinishedDeferred).then(jQuery.proxy(function() {
        var oView = this.getView();

        if (oParameters.name !== "detail") {
            return;
        }

        var sEntityPath = "/" + oParameters.arguments.entity;   
            this.bindView(sEntityPath);
        }, this));
},



bindView: function(sEntityPath) {
    var oView = this.getView();             
    oView.bindElement(sEntityPath); 


    //Check if the data is already on the client
    if (!oView.getModel().getData(sEntityPath)) {
        // Check that the entity specified was found.
        oView.getElementBinding().attachEventOnce("dataReceived", jQuery.proxy(function() {
        var oData = oView.getModel().getData(sEntityPath);
            if (!oData) {
                this.showEmptyView();
                this.fireDetailNotFound();
            } else {
                this.fireDetailChanged(sEntityPath);
            }
        }, this));

    } else {
        this.fireDetailChanged(sEntityPath);
    }
}, 

I've tried to implement this split app relative to the template generated by WebIDE. Any idea what is missing?


回答1:


As you wrote yourself, you are creating a "named Model" with the name "EMPL".

In the Controller you have to use the same name to get the Model:

this.getView().getModel("EMPL");

Likewise when calling bindElement() you have to give the model name:

// Assuming sEntityPath = "/items/0"
this.getView().bindElement("EMPL>" + sEntityPath);


来源:https://stackoverflow.com/questions/36179369/detail-page-of-split-app-without-model

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!