添加具有重复 ID 的元素 [英] adding element with duplicate id

查看:23
本文介绍了添加具有重复 ID 的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个 SAP Fiori 应用程序.我在 dialog 框中有 input ,因为我必须获取输入值.我在 fragment view 中定义对话框.

I am creating a SAP Fiori application. I have input in a dialog box in that I have to fetch the input value. I am defining the dialog in fragment view.

当我尝试为输入提供 id 时,我收到一个错误,因为添加了具有重复 id 的元素.

When I try to give the id for input I am getting an error as adding element with duplicate id.

------片段视图------

<core:FragmentDefinition
  xmlns="sap.m"
  xmlns:core="sap.ui.core"
  xmlns:app="http://schemas.sap.com/sapui5/extension/sap.ui.core.CustomData/1">
  <Dialog title="Title"  class="sapUiPopupWithPadding" >
    <content>  
        <HBox> 
           <items> 
              <Text  text="Name"></Text> 
              <Input  value="" id="myId"  > </Input> 
           </items> 
       </HBox> 
    </content>
    <beginButton>
        <Button text="Ok"  press="DialogButton" />
    </beginButton>
</Dialog>

---控制器代码---

DialogButton:function(oEvent) {

   var myIdValue=sap.ui.getCore().byId("myId").getValue();

   console.log("ID Value :::"+  myIdValue);

   oDialogFragment.close();

}

推荐答案

每次需要打开对话框时,您都会创建一个新的对话框片段实例.这将导致重复 ID 问题.请在您的控制器中保留一个对话框片段实例.

You create a new dialog fragment instance every time you need to open the dialog . This will cause the duplicated ID issue. Please keep a dialog fragment instance in your controller.

请看示例代码:

DialogButton:function(oEvent) {
   if(!this.oDialog) {
      this.oDialog =  sap.ui.xmlfragment("you.dialog.id", this );
   }
   this.oDialog.open();
}

这篇关于添加具有重复 ID 的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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