当前位置:网站首页>SAP UI5 确保控件 id 全局唯一的实现方法
SAP UI5 确保控件 id 全局唯一的实现方法
2022-08-04 19:31:00 【华为云】
stable ID 用于在运行时识别和修改控制器内的控件。 但是,如果您重用或嵌套这些视图,这些 stable ID 将不再是唯一的。 为了避免 id 冲突,每个 SAP UI5 视图都将自己的 ID 作为前缀添加到其所有子控件中。
看一个例子,下面这个 xml 视图里,Button 控件的 id 为:aButton
<mvc:View viewName="sap.hcm.ButtonView" controllerName="sap.hcm.myController" xmlns="sap.m" xmlns:mvc="sap.ui.core.mvc"> <Button id="aButton" text="Click me"/><mvc:View>
然后我定义了另一个 xml 视图,把上面这个包含了 button 控件的 xml 视图,嵌套进去:
<mvc:View viewName="sap.hcm.ContainerView" controllerName="sap.hcm.Address" xmlns="sap.ui.commons" xmlns:core="sap.ui.core" xmlns:html="http://www.w3.org/1999/xhtml"> <mvc:View id="ButtonView1" viewName="sap.hcm.ButtonView"/> <mvc:View id="ButtonView2" viewName="sap.hcm.ButtonView"/><mvc:View>
运行时,两个被嵌套的 xml 视图 id 为:
myContainerView–ButtonView1
myContainerView–ButtonView2
获取这些嵌入 xml 视图实例的代码:
var oButtonView1 = oView.byId("ButtonView1");
获取每个 xml 视图实例里的 button 实例的代码:
var oButton = oButtonView1.byId("aButton");
边栏推荐
猜你喜欢
ELECTRA:Pre-training Text Encoders as Discriminators Rather Than Generators
Highlights of some performance tests
入门:人脸专集1 | 级联卷积神经网络用于人脸检测(文末福利)
零基础做出高端堆叠极环图
Exploration and Practice of Database Governance
openharmony初体验(1)
NLP技术为何在工业界这么卷?前沿案例解析来了
【着色器实现Glitch单项故障闪烁效果(与Television效果不同)_Shader效果第十四篇】
Defaced Fingerprint Recovery and Identification
编译optimize源码实现过程
随机推荐
STP实验
致-.-- -..- -
【ASP.NET Core】 中间件
我的四周年创作纪念日
MMDetection usage example: from entry to exit
八一建军节 | 致敬中国人民解放军
MySQL远程备份策略举例
污损指纹恢复与识别
【Attention演变史】翻译模型seq2seq (第二弹)
编译optimize源码实现过程
openharmony代码框架初识(2)
PG网络传输安全SSL介绍及使用示例
openharmony初体验(1)
Openharmony code framework (2) the person that
T+Cloud: A "Smart Company" for Building New Business Social Networks and Marketing Relationships
visual studio 与 visual studio code
TritonVM——基于Recursive STARK的虚拟机
SAP UI5 视图控制器 View Controller 的生命周期方法 - Lifecycle methods
Defaced Fingerprint Recovery and Identification
Highlights of some performance tests