How to get the reference to the another view contr

2019-09-10 06:25发布

问题:

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();
      ....
      ....
      ....

    }


标签: sapui5