如何在某个视图中获取对另一个视图控件的引用?
How to get the reference to the another view control within some view?
"ViewA.view.js" 创建的 ViewA 绑定到 JSONModel。从名为 ViewB 的视图中,我想获取 ViewA 绑定到的 JSONModel 中的数据。
我怎样才能在 "ViewB.view.js" 中获取对 ViewA 的引用?
您可以通过使用视图的 viewData 属性 来完成。
假设您有一个模型:ViewA 中的 oModel。
当您在 ViewA 中调用新视图 (ViewB) 时,只需执行以下操作。
var oViewB = sap.ui.view({
viewName: "myApp.ViewA",
type: sap.ui.core.mvc.ViewType.<type>,
viewData: oModel.getData()
});
在 ViewB 的 createContent 中:
createContent: function(oController) {
var oDataFromViewA = this.getViewData();
....
....
....
}
一般来说,紧密耦合视图以共享模型数据并不是最佳做法。更好的方法是使用在所有视图中都可用的全局模型。您可以通过调用 sap.ui.getCore().setModel(modelInstance, modelName).
来完成此操作
"ViewA.view.js" 创建的 ViewA 绑定到 JSONModel。从名为 ViewB 的视图中,我想获取 ViewA 绑定到的 JSONModel 中的数据。 我怎样才能在 "ViewB.view.js" 中获取对 ViewA 的引用?
您可以通过使用视图的 viewData 属性 来完成。
假设您有一个模型:ViewA 中的 oModel。
当您在 ViewA 中调用新视图 (ViewB) 时,只需执行以下操作。
var oViewB = sap.ui.view({
viewName: "myApp.ViewA",
type: sap.ui.core.mvc.ViewType.<type>,
viewData: oModel.getData()
});
在 ViewB 的 createContent 中:
createContent: function(oController) {
var oDataFromViewA = this.getViewData();
....
....
....
}
一般来说,紧密耦合视图以共享模型数据并不是最佳做法。更好的方法是使用在所有视图中都可用的全局模型。您可以通过调用 sap.ui.getCore().setModel(modelInstance, modelName).
来完成此操作