SAP UI5:绑定详细信息页面时出错



我的母版中有以下代码:

onInit: function () {
var me = this;
jQuery.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
url: "RESTAPI",
dataType: "json",
success: function (response, status, xhr) {
debugger;
var oView = me.getView();
var oModel = new sap.ui.model.json.JSONModel();
oModel.setData(response);
oView.setModel(oModel);
}
});
me.mBindingOptions = {};
me.oRouter = sap.ui.core.UIComponent.getRouterFor(this);  
me.oRouter.getTarget("listainvestimento").attachDisplay(
jQuery.proxy(me.handleRouteMatched, me));
},
_onListItemPress: function (oEvent) {
var context = oEvent.getParameter("listItem").getBindingContext().getPath().substr(1).split("/")[1]
//context="0" (position in my array model)
var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
oRouter.navTo("detalheinvestimento", {
ctx: context
}, false);
}

在我的详细信息页面中:

onInit: function () {
this.oRouter = sap.ui.core.UIComponent.getRouterFor(this);
this.oRouter.getTarget("detalheinvestimento").attachDisplay(jQuery.proxy(this.handleRouteMatched, this));
},
handleRouteMatched: function (oEvent) {
this.getView().bindElement({
path: "/" + oEvent.getParameter("arguments").ctx
});
}

Manifest.json

{
"pattern": "listainvestimento/detalheinvestimento/{ctx}",
"name": "detalheinvestimento",
"target": [ "listainvestimento", "detalheinvestimento" ]
},

有关更多信息,我已经在 Build.me 中创建了原型屏幕,现在我正在链接到我的实际服务器数据。

主控中的绑定成功发生,但不是细节。

我不知道错误在哪里,模型正在主控中设置,但是当它到达细节时,它没有链接。

绑定的字段名称正确!

有人可以帮助我吗?

  1. JSON 模型仅存在于母版页中,因为您要在控制器 onInit 方法上创建它。它不会在详情页面/控制器中自动提供。您应该在 manifest.json 中定义您的模型,以便它在应用程序的所有组件(包括所有视图(中都可用。查看此链接以获取有关如何在清单中执行此操作的信息。

https://blogs.sap.com/2016/10/11/sapui5-load-local-json-model-directly-manifest.json/

  1. json 模型可以将 rest API 的 URL 作为参数,你不需要做 jquery.ajax 调用并处理成功案例。

相关内容

最新更新