on 2016 May 28 12:30 PM
Hello,
I try to define several OData model asynchronously.
Here how I define them (all OData models declarations are grouped in a separate function):
var oODataModel = new sap.ui.model.odata.ODataModel(
"url1", {
loadMetadataAsync: true
}).attachMetadataLoaded(function(){
that.getView().setModel(oODataModel, "model1_odata");
});
oODataModel = new sap.ui.model.odata.ODataModel(
"url2", {
loadMetadataAsync: true
}).attachMetadataLoaded(function(){
that.getView().setModel(oODataModel, "model2_odata");
});
and so on.
The problem is that further in code I need to call to those "modelX_odata" models and do reads, while the models are still not set (async calls are still in progress).
Is there a way to wait for all those models are complete calls and are set?
Thank you,
Yuri
you can set model directly, why wait until the metadata loaded?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That's not the problem. The problem is that I do read() before the model is finished the declaration (before the metadata is loaded). And this returns me an error.
Is there a way to declare several OData models using deferreds?
Like,
doDeclare: function(){
var oODataModel1 = new sap.ui.model.odata.ODataModel("url1", {
loadMetadataAsync : true
});
this.getView().setModel(oODataModel1, "odata1");
var oODataModel2 = new sap.ui.model.odata.ODataModel("url2", {
loadMetadataAsync : true
});
this.getView().setModel(oODataModel2, "odata2");
},
doContinue: function(){
//do stuff here
}
And do something like:
$.when(this.doDeclare()).done(this.doContinue());
so all async calls and metadata loads in doDeclare() are finished before doContinue() starts?
If this was a regular ajax call, I'd do something like this and it would work fine, but this is sapui5 odata declaration, and I'm not sure how to deal with it.
I have one function which makes read() (read(sPath, mParameters?): object) calls to different OData models and, of course, the path (sPath) to the required data is different every time. I need metadata to get that path dynamically, without hardcoding it.
I didn't find any way to achieve it without using metadata, but if there is one, I'd be glad to learn it.
Hi Yuri,
it may also be depending on where you are loading these odata models.
1) are your url and url2 valid URLs?
2) are you doing this on the Component.js file during the init function? (based on your JS code)
have you tried loading them from the manifest.json file ?
check out this blog and see if this helps you.
hope it helps!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
thank you for the answer.
1) urls are valid. if I change loadMetadataAsync property to false, everything works fine.
2) I define models during onBeforeRendering stage in controller. I plan to use the app with Fiori Launchpad, so I need to do all definitions during onBeforeRendering stage, because onAfterRendering hook runs only once - if I open app on Fiori Launchpad for the second time, onAfterRendering hook won't run.
User | Count |
---|---|
76 | |
10 | |
10 | |
10 | |
10 | |
9 | |
8 | |
7 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.