【发布时间】:2018-09-21 01:13:53
【问题描述】:
在视图数据绑定成功后,我正在尝试执行一些操作。在我看来,最好的办法是在 attachModelContextChange 方法的回调中进行。在定义哪个方法将作为回调并将事件侦听器附加到视图后,当我尝试将数据绑定到我的视图时,我收到错误:无法读取未定义的属性“调用”。我在下面粘贴我的控制器代码片段和堆栈跟踪。
onInit: function() {
var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
oRouter.attachRouteMatched(this.routeMatched, this);
},
routeMatched: function(oEvent) {
var sEntityPath,
oParameters = oEvent.getParameters();
this.routeName = oParameters.name;
this.getView().detachModelContextChange(
this.modelCallback('edit'),
this.getView()
);
if (oParameters.name === "EditItem") {
if (!isNaN(oParameters.arguments.id)) {
this.getView().attachModelContextChange(null,
this.modelCallback('edit'),
this.getView()
);
sEntityPath = "/ItemData(" + oParameters.arguments.id + ")";
this.getView().bindElement(sEntityPath);
} else {
var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
oRouter.navTo("CreateItem", {
from: "EditItem"
}, false);
}
}
},
modelCallback: function(type) {
console.log(type);
}
modelCallback 方法中的 console.log 正在正常启动。删除与
行this.getView().bindElement(sEntityPath);
防止错误触发(但这样我当然不会在我的视图中获得任何数据)。
任何想法我错过了什么?
下面我粘贴堆栈跟踪:
datajs.js:17 Uncaught TypeError: Cannot read property 'call' of undefined
at f.a.fireEvent (sap-ui-core.js:449)
at f.a.fireEvent (sap-ui-core.js:991)
at f.fireModelContextChange (sap-ui-core.js:573)
at f.h.setElementBindingContext (sap-ui-core.js:524)
at constructor.i (sap-ui-core.js:500)
at constructor.a.fireEvent (sap-ui-core.js:449)
at constructor.B._fireChange (sap-ui-core.js:1302)
at eval (library-preload.js:2375)
at u (library-preload.js:2460)
at d.r._processSuccess (library-preload.js:2492)
【问题讨论】:
标签: javascript binding sapui5