操作使用“byId"访问的控件没有效果 [英] Manipulating control accessed with "byId" has no effect

查看:29
本文介绍了操作使用“byId"访问的控件没有效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 XML 视图中的 HBox 中有一个图标示例,如下所示:

I have a sample of icons in a HBox in an XML view as below:

<m:HBox>
  <core:Icon src="sap-icon://show" color="#007bff" id="test1"  press="onPressView" />
  <core:Icon src="sap-icon://edit" color="#007bff" id="test2" press="onPressEdit" />
  <core:Icon src="sap-icon://print" color="#007bff" id="test3" press="onPressPrint" />
</m:HBox>

在控制器中设置可见false,我这样做:

In controller to set visible false, I am doing as:

let testIcon1 = this.getview().byId('test1');
testIcon1.setVisible(false);

但这不起作用.

推荐答案

您可能正在访问模板控件而不是实际呈现的控件.如果您检查 devtools 中的元素,请查看呈现的控件(图标)的 ID 是否具有后缀 __clone.

You're probably accessing a template control instead of the actual rendered one. If you inspect the element in the devtools, see if the ID of the rendered control (Icon) has the suffix __clone<n>.

由于此类 ID 后缀是由框架生成的,因此应避免通过 byId 访问克隆控件.在这种情况下有许多替代解决方案.一般好的解决方案是通过绑定控件属性(例如 visible)并从模型中操作这些属性来将视图与控制器分开.

Since such ID suffixes are generated by the framework, accessing cloned controls via byId should be avoided. There are many alternative solutions in such cases. A general good solution is to separate views from the controller by binding the control properties (e.g. visible) and manipulating those properties from the model.

这篇关于操作使用“byId"访问的控件没有效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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