on 12-13-2016 12:06 PM
I'm trying to retrieve an OData model from inside onInit function from a controller in SAPUI5 for storing a property into a local variable. I have tried the following without success:
var oModel = this.getView().getModel();// returns undefined
var oModel = sap.ui.getCore().getModel();// returns undefined
I have googled the problem, and it seems like the model is not yet set when the onInit() is running. Because of this, I have tried:
var oModel = this.getOwnerComponent().getModel(); // returns empty odata object
var value = oModel.getProperty("/Collection/Property"); // returns undefined
The exact same code works just fine in all other functions except onInit(), but I need it inside this function.
How can I retrieve the model and property in onInit?
I think the onBeforeRendering should only run the first time the view is loaded... otherwise, you can check if the model is instantiated or set a property after it is instantiated so you can skip the validation on subsequent runs ,... maybe this would work
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
would it meet your requirement if you add it on the onBeforeRendering() event instead of the onInit() event?
your model will be ready from there onwards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.