on 03-18-2021 1:32 PM
Hello,
My code for the request is:
onInit: function () {
var oModel = this.getOwnerComponent().getModel();
var sPath = "/myPath";
var oFilters = [];
var filter = new Filter("Name", FilterOperator.EQ, "Fotios");
oFilters.push(filter);
var that = this;
oModel.read(sPath, {
filters: oFilters,
success: function (oData, oResponse) {
var data = new JSONModel(oData.results);
that.getView().setModel(data, "Data");
console.log(that.getView().getModel("Data").getData()); //This prints the data
},
error: function (oError) {
console.log(oError);
}
}).then(this.getView().byId("MyTable").setModel(data))
console.log(this.getView().getModel("Data").getData());
},
The console.log inside the success of the request is logging the data successfully.
The console.log at the end of the onInit function doesn't.
The .then() after the read() gives an error that it is not a function
I want to get the data as I do and either set it inside the success so I can use them in the View OR to use the .then() so I can do stuff after the data are in the component.
YOURFUNCTIONNAME: function () {
return new Promise(function (resolve, reject) {
oModel.read(sPath, {
filters: oFilters,
success: function (oData, oResponse) {
resolve(oData);
},
error: function (oError) {
reject(oError);
}
})
},
// call YOURFUNCTIONNAME
this.YOURFUNCTIONNAME().then(*****)
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 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.