没有模型的拆分应用程序的详细信息页

Detail page of split app without model

本文关键字:详细信息 应用程序 拆分 模型      更新时间:2023-09-26

在我的拆分应用程序中,详细视图不绑定任何模型。

component.js中,我实例化了一个命名模型,如下所示:

// 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");

主视图控制器中的方法onSelect是通过单击列表项来激发的。

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

这将调用方法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); 
},

在细节视图的控制器中,我有这两种更新绑定的方法。onRouteMatched调用bindView,在那里我得到错误消息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);
    }
}, 

我已经尝试实现这个相对于WebIDE生成的模板的拆分应用程序。知道缺了什么吗?

正如您自己写的,您正在创建一个名为"EMPL"的"命名模型"。

在控制器中,您必须使用相同的名称才能获得型号:

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

同样,当调用bindElement()时,您必须提供型号名称:

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