如何在控制器外检索视图 - Openui5 [英] How to retrieve View outside the controller - Openui5
问题描述
如果我在视图的控制器中使用 this.getView()
,我可以毫无问题地检索它.如果我在控制器之外(例如在另一个视图的控制器中),我如何检索视图?
If I use this.getView()
inside the controller of a view I can retrieve it without problems.
How can I retrieve the view if I am outside the controller (e. g. in controller of another view)?
我尝试了 sap.ui.core.Core().byId("
但它返回 undefined
.
I try sap.ui.core.Core().byId("<name of view>")
but it returns undefined
.
推荐答案
您可以使用以下方法实例化另一个视图:
You can instantiate another view using:
var view = sap.ui.jsview("<name of view>");
如果您使用不同的视图类型,您可以从 这里.
If you´re using different view types you can choose the necessary function from here.
为了避免多次实例化,你可以这样做:
To avoid multiple instantiation you could do something like this:
var view = sap.ui.getCore().byId("id");
if (view === undefined) {
view = sap.ui.jsview("id", "<name of view>");
}
有关视图定义/实例化和 ID 的更多详细信息,请参阅此.
See this for more details regarding view definition/instantiation and IDs.
这篇关于如何在控制器外检索视图 - Openui5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!