javascript 如何在控制器外检索视图 - Openui5

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24267621/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 02:29:07  来源:igfitidea点击:

How to retrieve View outside the controller - Openui5

javascriptsapui5

提问by padibro

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)?

如果我this.getView()在视图的控制器内部使用,我可以毫无问题地检索它。如果我在控制器之外(例如在另一个视图的控制器中),我如何检索视图?

I try sap.ui.core.Core().byId("<name of view>")but it returns undefined.

我尝试sap.ui.core.Core().byId("<name of view>")但它返回undefined

采纳答案by Tim Gerlach

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>");
}

See thisfor more details regarding view definition/instantiation and IDs.

对有关视图定义/实例和ID的更多细节。

回答by padibro

When I create a view i set a id

当我创建一个视图时,我设置了一个 id

var theView=sap.ui.xmlview("OperationDetail, "<name of view>");

then i retrieve it by id

然后我通过 id 检索它

var theView = sap.ui.core.Core().byId("OperationDetail");
var myPage=theView.byId("pageOperation");

回答by user7017477

varRequired = sap.ui.getCore().byId("<name of view>");

thiskeyword refers to only the particular controller where as sap.ui.getCore()refers to the project views.

this关键字仅指特定控制器,其中 assap.ui.getCore()指的是项目视图。