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.
The following 3 lines in the success solved the issue:
var data = new JSONModel();
data.setProperty("/List", oData.results);
that.getView().setModel(data, "Data")
And then the binding on the table was like this:
<Table id="idAvvisiTable" items="{Data>/List}">
...
<Text text="{Data>AnyPropery}>
Since this is an async function it is obvious why it doesn't console.log at the end of the onInit function. But how can I make use of the .then() after the .read() ?
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.