on 06-27-2016 8:10 AM
Hi,
Have defined a model in the manifest.json:
"models": {
"tiles": {
"type": "sap.ui.model.json.JSONModel",
"uri": "model/tiles.json"
}
}
tiles.json looks like this, purpose is to define a set of tiles which will influence UI control content of a view
{
"tiles": {
"tile": [{
"id": "GT1",
"type": "genericTile1"
}]
}
}
Problem
On first pass of the lifecycle hooks in app.controller.js - onInit, onBeforeRendering, onAfterRendering - the model is not available to the view with
var mTileInfo = this.getView().getModel("tiles");
Results in mTileInfo undefined. As stated earlier, the model is to be used to influence the control content of the view before rendering.
Would seem that during first pass of hooks the view is not yet placed in the control root, and therefore at this point the component is not the parent where the model has been instantiated?
Tyhe model is available within the view after view has been rendered, checked in debug upon raising of event for button for example, but by this time too late to influence first view render.
Grateful for suggestions on how to resolve, many thanks
Former Member
In your onInit try using
this.getOwnerComponent().getModel("tiles");
Regards,
Jamie
SAP - Technology RIG
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jamie,
Many thanks for the reply and help, unfortunately it does not give me what I'm trying to achieve.
Model after using your suggestion in onInit of app controller in lifecycle first pass - in oData of model there is not tiles object or tile array.
Placing a button on the view simply to view the odata of model after first complete lifecycle pass, we can clearly see the tiles object (defined in tiles.json). My goal is to achieve this fully qualified odata property during first pass to control view content as determined by the json configuration:
Any ideas? Thanks very much.
Just following up on proposal to use:
var mTileInfo = this.getOwnerComponent().getModel("tiles");
Writing contents of mTileInfo shows tiles model in odata property:
console.log(mTileInfo);
In order to access model properties, I use the below within onInit of the controller. Unfortunately returns undefined
console.log(mTileInfo.getProperty("/tiles/tile"));
However If I declare a variable with exact same JSON notation, for example, and write out property, all is good. Grateful for suggestion.
var data = { | ||||||
"tiles": { | ||||||
"tile": [{ | ||||||
"id": "GT1", | ||||||
"type": "genericTile1" | ||||||
}] | ||||||
} | ||||||
} |
var gConfigModel = new sap.ui.model.json.JSONModel(data); | |
console.log(gConfigModel.getProperty("/tiles/tile")); |
User | Count |
---|---|
74 | |
8 | |
8 | |
8 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.