Manipulating control accessed with “byId” has no effect

谁说胖子不能爱 提交于 2021-01-29 16:14:34

问题


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>

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

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

But this isn't working.


回答1:


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>.

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.



来源:https://stackoverflow.com/questions/61674679/manipulating-control-accessed-with-byid-has-no-effect

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!