【问题标题】:Detail page of split app without model没有模型的拆分应用的详细信息页面
【发布时间】:2016-07-10 19:33:10
【问题描述】:

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

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 生成的模板来实现这个拆分应用程序。知道缺少什么吗?

【问题讨论】:

    标签: javascript binding sapui5 model-binding master-detail


    【解决方案1】:

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

    在Controller中你必须使用相同的名字来获取Model:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多