on 2022 Feb 07 9:42 PM
I have JSONModel defined in manifest. When arrive in oninit of Page1 of app, my model is sometimes not loaded.
Line below sometimes errors as model is not loaded:
var oServlet = this.getOwnerComponent().getModel().getProperty("/Rowsets/Rowset/0/Row");
Is attachRequestCompleted needed in controller code, or is there a newer/better way to do this in SAPUI5?
Would a promise be better?
If so, can I use promise with JSONModel?
If so, how?
I have noticed a UI5 function in some online examples: oModel.metadataLoaded(true).then(...
Is "metadataLoaded" function only for OData models?
If so, is there a related JSON function other than attachRequestCompleted?
If attachRequestCompleted is needed, must I recreate the model. Example:
var oModel = new JSONModel(); // >>> This seems inefficient as model is already defined in manifest?
oModel.attachRequestCompleted(){function(){
console.log("manifest model is loaded.")
}
Manifest entries
Is "type" required in mainService?
"dataSources": {
"mainService": {
"uri": "/XMII/PropertyAccessServlet?Mode=List&content-type=text/json",
"type": "JSON"
}
},
Is "type" required in ""?
"models": {
"": {
"dataSource": "mainService",
"type": "sap.ui.model.json.JSONModel",
"preload": true
}
},
I am new to UI5 and would like to learn!
Thanks very much for any information that can be provided.
Help others by sharing your knowledge.
AnswerRequest clarification before answering.
Since UI5 1.64, JSONModel provides the API dataLoaded() that returns a promise (which is similar to the `metadataLoaded(true)` in v2.ODataModel). Take a look at https://stackoverflow.com/a/63892279/5846045.
doSomethingWith: async function (myJSONModel) {
await myJSONModel.dataLoaded(); // since UI5 v1.64
const data = myJSONModel.getProperty("/...");
},
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This code has allowed me to create a solution that is working! Thank you very much for the example and the links!
User | Count |
---|---|
75 | |
30 | |
9 | |
8 | |
7 | |
6 | |
6 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.