ViewA created by "ViewA.view.js" is bound to a JSONModel. From within a view called ViewB, I would like to get the data in the JSONModel to which ViewA is bound. How can I possibly get the reference to ViewA within "ViewB.view.js"?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
In general it's not a best practice to tightly couple views to share model data. A better approach is to use a global model which is available in all your views. You do this by calling sap.ui.getCore().setModel(modelInstance, modelName).
回答2:
You can do by using viewData property of a view.
Suppos you have a model : oModel in ViewA.
When you call a new view (ViewB) inside ViewA just do the followings.
var oViewB = sap.ui.view({
viewName: "myApp.ViewA",
type: sap.ui.core.mvc.ViewType.<type>,
viewData: oModel.getData()
});
inside ViewB's createContent:
createContent: function(oController) {
var oDataFromViewA = this.getViewData();
....
....
....
}