on 2022 Dec 09 11:58 AM
Hello All,
I have created a custom UI5 application.
But while reading the data through the following query, I am getting an error- “Uncaught TypeError: Cannot read properties of undefined (reading 'getView') at success”
this.oModel.read("/ET_Deal_CustListSet", {
success: function (odata) {
var CustJsonData = new JSONModel(odata.results);
this.getView().setModel(CustJsonData, "ET_CustList");
}
});
I can view the data in Network tab - $metadata(status: 200), $batch(status: 202). But this odata query results in an error.
Please advise.
Regards- Meenakshi
Hi,
You need to bind "this" to the success callback fn:
this.oModel.read("/ET_Deal_CustListSet", {
success: function (odata) {
var CustJsonData = new JSONModel(odata.results);
this.getView().setModel(CustJsonData, "ET_CustList");
}.bind(this)
});
or save the outer context and use it in the scope of the success callback fn:
var that = this;
this.oModel.read("/ET_Deal_CustListSet", {
success: function (odata) {
var CustJsonData = new JSONModel(odata.results);
that.getView().setModel(CustJsonData, "ET_CustList");
}
});
Br,
Radoslaw
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi meenakshi.raina, inside a function, "this" is not referencing to the controller as you assume. The easiest way to fix this is to use the arrow function. This will look like this:
this.oModel.read("/ET_Deal_CustListSet", {
success: (odata) => {
var CustJsonData = new JSONModel(odata.results);
this.getView().setModel(CustJsonData, "ET_CustList");
}
});
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
70 | |
11 | |
10 | |
10 | |
9 | |
9 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.