I'm getting error with getBindin function.I have to filter data as soon as the page loads.I have made a split app where in master page after user clicks on the name of the user all the details are displayed in the detailsPage.This code is for the detailsPage.I'm getting the following error
TypeError: Cannot read property 'getBinding' of undefined
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");
}
});
});
By the error message it seems that instead of having a problem in the data binding, you are failing to get the list using sap.ui.getCore().byId
.
Assuming you have a XML view or created ids using createId
method, you should use methods this.byId()
or this.getView().byId()
to get the list.
Tip: Usually when you have an error like Cannot read property 'XXX' of undefined
usually the error is in the variable you use before XXX.
As the oList
variable is undefined, you are getting this error.