页面加载后 getBinding 不起作用
getBinding is not working after the page loads
我在使用 getBindin 时遇到错误 function.I 必须在页面 loads.I 生成拆分应用程序后立即过滤数据详细信息显示在 detailsPage.This 代码中 detailsPage.I 出现以下错误
TypeError: 无法读取未定义的 属性 'getBinding'
return Controller.extend("com.Second.SecondProject.controller.SecondPage", {
onInit: function () {
var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
oRouter.getRoute("DetailsPage").attachMatched(this._onObjectMatched, this);
},
_onObjectMatched: function (oEvent) {
var selectedArguments = oEvent.getParameter("arguments");
var selectedRecord = selectedArguments.value;
console.log(selectedRecord);
var oList = sap.ui.getCore().byId("UserList");
var oBinding = oList.getBinding("users");
console.log(oBinding);
var aFilter = [];
aFilter.push(new Filter("name", FilterOperator.Contains, selectedRecord));
oBinding.filter(aFilter);
// var obj = {
// "Objects": selectedRecord
// };
// var navigationobjModel = new JSONModel();
// navigationobjModel.setData(obj);
// this.getView().setModel(navigationobjModel, "users");
}
});
});
根据错误消息,您似乎没有在数据绑定中遇到问题,而是无法使用 sap.ui.getCore().byId
获取列表。
假设您有一个 XML 查看或使用 createId
方法创建的 ID,您应该使用方法 this.byId()
或 this.getView().byId()
来获取列表。
提示:通常当您遇到类似 Cannot read property 'XXX' of undefined
的错误时,通常错误出在您在 XXX 之前使用的变量中。
由于 oList
变量未定义,您会收到此错误。
我在使用 getBindin 时遇到错误 function.I 必须在页面 loads.I 生成拆分应用程序后立即过滤数据详细信息显示在 detailsPage.This 代码中 detailsPage.I 出现以下错误
TypeError: 无法读取未定义的 属性 'getBinding'
return Controller.extend("com.Second.SecondProject.controller.SecondPage", {
onInit: function () {
var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
oRouter.getRoute("DetailsPage").attachMatched(this._onObjectMatched, this);
},
_onObjectMatched: function (oEvent) {
var selectedArguments = oEvent.getParameter("arguments");
var selectedRecord = selectedArguments.value;
console.log(selectedRecord);
var oList = sap.ui.getCore().byId("UserList");
var oBinding = oList.getBinding("users");
console.log(oBinding);
var aFilter = [];
aFilter.push(new Filter("name", FilterOperator.Contains, selectedRecord));
oBinding.filter(aFilter);
// var obj = {
// "Objects": selectedRecord
// };
// var navigationobjModel = new JSONModel();
// navigationobjModel.setData(obj);
// this.getView().setModel(navigationobjModel, "users");
}
});
});
根据错误消息,您似乎没有在数据绑定中遇到问题,而是无法使用 sap.ui.getCore().byId
获取列表。
假设您有一个 XML 查看或使用 createId
方法创建的 ID,您应该使用方法 this.byId()
或 this.getView().byId()
来获取列表。
提示:通常当您遇到类似 Cannot read property 'XXX' of undefined
的错误时,通常错误出在您在 XXX 之前使用的变量中。
由于 oList
变量未定义,您会收到此错误。