SAPUI5绑定JSON模型来控制

时间:2016-05-24 10:55:31

标签: sapui5 jsonmodel

我是ABAPer并且正在学习.link1。我正在通过SAPUI5控制练习大师级细节应用程序。我一直在寻找这种例子,但没有发现任何。所以,我在这里写。如果可能请指导我。

我正在使用本地JSON模型(名为Products.json的文件中的条目)。我有两个视图 first.xml seconds.xml ,它们分别是主视图和详细信息。

在第一个视图中,我有一个列表,下面是在此列表的splitApp事件中编写的代码

onItemSelect

var oSelectedItem = oEvent.getSource(); var oContext = oSelectedItem.getBindingContext("products"); var sPath = oContext.getPath(); var oPrdDetails = sap.ui.xmlview("view.second").byId("prdDetails"); oPrdDetails.bindElement({ path: sPath, model: "products" }); var oListDetails = sap.ui.xmlview("view.second").byId("listDetails"); oListDetails.bindElement({ path: sPath, model: "product2" }); 是第二个视图中的面板,Id="prdDetails"是第二个视图中的列表。我的问题是这些控件没有使用上面的代码进行更新。

1 个答案:

答案 0 :(得分:0)

SAPUI5开发人员指南包含Walkthrough tutorial中的必要步骤。建议在Master-Detail的情况下通过导航执行此操作。

在onItemSelect()中,您可以使用此代码段导航到路线:

var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
oRouter.navTo("detail", {
    invoicePath:     oItem.getBindingContext("invoice").getPath().substr(1)
});

在详细视图中,您必须订阅模式匹配事件,如下所示:

oRouter.getRoute("detail").attachPatternMatched(this._onObjectMatched, this);

当请求正确的URL哈希时,框架将调用指定的this._onObjectMatched

_onObjectMatched: function (oEvent) {
    this.getView().bindElement({
        path: "/" + oEvent.getParameter("arguments").invoicePath,
        model: "invoice"
    });
}

如果将元素绑定到UI,则可以相对地为视图中的控件指定属性({propName})。

当然,您必须为您的应用程序设置routing和component.js,但演练中也对此进行了描述。

示例应用程序可以从here(右上角的“下载”按钮)下载

相关问题