2016-11-05 62 views
1

我需要OpenUI5的幫助。我在視圖中創建按鈕,並通過單擊按鈕它創建對話框窗口並拋出一個錯誤,所以我不能進入對話框的功能。在OpenUI5中創建對話框時出現重複的ID

按鈕鑑於:

<m:Button text="{i18n>RESULTS_CHANCES_SEND_EMAIL}" 
      class="sapUiMediumMarginBegin results-button" 
      tap="sendToEmail" 
      press="sendToEmail" 
      icon="sap-icon://email"> 

功能的控制器:

sendToEmail: function() { 

    var email = new Dialog({ 
     title: 'שליחת תוצאות לדוא"ל', 
     type: 'Message', 
     content: [ 
     new Input('submitEmailInput', { 
      liveChange: function (oEvent) { 
      var sText = oEvent.getParameter('value'); 
      var parent = oEvent.getSource().getParent(); 

      parent.getBeginButton().setEnabled(sText.length > 0); 
      }, 
      width: '100%', 
      placeholder: 'דואר אלקטרוני' 
     }) 
     ], 
     beginButton: new Button({ 
     text: 'שליחה', 
     enabled: false, 
     icon: 'sap-icon://email', 
     press: function() { 

      //var sText = sap.ui.getCore().byId('submitEmailInput').getValue(); 
      //MessageToast.show('Email is: ' + sText); 

      // here comes the API request 
      email.close(); 
     } 
     }), 
     endButton: new Button({ 
     text: 'סגירה', 
     icon: 'sap-icon://decline', 
     press: function() { 
      email.close(); 
     } 
     }), 
     afterClose: function() { 
     email.destroy(); 
     } 
    }); 

    email.open();} 

錯誤:duplicate id

非常感謝!

+0

我正在學習UI5。我想我會在某個地方看到破壞可能會將HTML元素留在dom中。也許谷歌與其他案件相關的使用片段和銷燬。 –

回答

0

你已經附加了相同的事件處理程序來「點擊」和「按下」事件,所以sendToEmail被調用兩次(並且第二次具有相同ID的控件已經存在)...刪除「tap」,因爲這是貶值,所以你最終應該:

<m:Button text="{i18n>RESULTS_CHANCES_SEND_EMAIL}" 
     class="sapUiMediumMarginBegin results-button" 
     press="sendToEmail" 
     icon="sap-icon://email">