sap.ui.getCore().byId() 不返回任何元素 [英] sap.ui.getCore().byId() returns no element

查看:39
本文介绍了sap.ui.getCore().byId() 不返回任何元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个 UI5 应用程序,现在想使用 sap.ui.getCore().byId(id) 访问现有控件.在同一个控制器/视图中,我可以通过 this.byId(id) 访问它们,但要访问其他文件(例如控制器)中的控件,我需要 sap.ui.getCore().byId(id).

I created an UI5 app and now want to use sap.ui.getCore().byId(id) to access existing controls. In the same controller/view I can access them via this.byId(id), but to access controls in other files (e.g. controllers) I need sap.ui.getCore().byId(id).

然而,虽然 sap.ui.getCore() 返回一个核心对象,但我无法通过它的 byId() 函数访问控件,我得到 undefined 代替.我已经构建了一个 UI5 应用程序,并且我对这个函数调用没有任何问题.

However, while sap.ui.getCore() returns a core object, I cannot access controls via the byId() function of it, I get undefined instead. I already built an UI5 app and there I have no issue with this function call.

我需要配置什么才能让它工作吗?

Is there something I have to configure for this to work?

推荐答案

如果你查看视图的 byId 方法,你可以看到它在视图 ID 前面加上了,它本质上调用了 sap.ui.getCore().byId(this.createId(id)).

If you look into the view's byId-method, you can see that it prepends the views ID, it essentially calls sap.ui.getCore().byId(this.createId(id)).

这样您就可以多次实例化一个视图,而不会产生重复的 ID.为了从外部访问控件,您要么需要视图以便您可以调用 view.byId(id),或者您必须像这样手动将视图的 ID 与 ID 连接起来:sap.ui.getCore().byId(viewId + "--" + id).

This is so that you can instantiate a view several times without having duplicate IDs. In order to access the controls from the outside, you either need the view so you can call view.byId(id), or you have to manually concatenate the view's ID with the ID like this: sap.ui.getCore().byId(viewId + "--" + id).

这篇关于sap.ui.getCore().byId() 不返回任何元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆