2016-12-23 71 views
0

所以...我正在構建一個基本上是CRUD的應用程序。SAPUI5 - 重複ID不同的控制器

在此應用程序中,我有以下視圖/控制器:VisitEditRequestNew

RequestNew控制器I有一個處理一個按鈕的按壓的功能:

onRequestNewAddCustomerPress: function(oEvent){ 
      if(!this.oAddCustomerDialog){ 
       this.oAddCustomerDialog = sap.ui.xmlfragment("com.sap.lccapp.fragment.AddCustomer", this); 
      } 
      this.oAddCustomerDialog.openBy(oEvent.getSource()); 
     }, 

和我在此相同的控制器上的的OnExit功能。它現在是空的,因爲我用這個對象的.destroy()函數做了很多測試(oAddCustomerDialog),它繼續彈出錯誤。


的問題是,在VisitEdit控制器上,當我嘗試使用同一個對話框第二次,用下面的代碼:

onVisitEditAddCustomerPress: function(oEvent){ 
    if(!this.oAddCustomerDialog){ 
     this.oAddCustomerDialog = sap.ui.xmlfragment("com.sap.lccapp.fragment.AddCustomer", this); 
    } 
    this.oAddCustomerDialog.openBy(oEvent.getSource()); 
}, 

它顯示了follwing錯誤:「添加帶有重複ID」addCustomerNameField「的元素」

該ID爲'addCustomerNameField'來自我的片段中的第一個元素。


If you guys didn't understand what is going on, here is the following explanation that needs an answer:

Although I have the 'if verification' on both methods and because it is in different controllers, the last 'if' that is being verified has the object (this.oAddCustomerDialog) undefined (BUT IT SHOULD NOT HAS UNDEFINED VALUE) and it is creating again the sap.ui.xmlfragment....


+0

你可以添加Fragement代碼太 –

+0

@AnilTalla那就是:http://dontpad.com/stackoverflowquestionsapui5 –

回答

0

您可以實例化片段時,一個唯一的ID相關聯。這樣,這個唯一的ID將以它所包含的控件的ID爲前綴。

因此,兩種不同的代碼將是:

onRequestNewAddCustomerPress: function(oEvent){ 
      if(!this.oAddCustomerDialog){ 
       this.oAddCustomerDialog = sap.ui.xmlfragment("idOnNewRequest","com.sap.lccapp.fragment.AddCustomer", this); 
      } 
      this.oAddCustomerDialog.openBy(oEvent.getSource()); 
     }, 

然後:

onVisitEditAddCustomerPress: function(oEvent){ 
    if(!this.oAddCustomerDialog){ 
     this.oAddCustomerDialog = sap.ui.xmlfragment("idOnEdit","com.sap.lccapp.fragment.AddCustomer", this); 
    } 
    this.oAddCustomerDialog.openBy(oEvent.getSource()); 
}, 

另外,不要查看以下鏈接:

https://help.sap.com/saphelp_nw74/helpdata/en/07/15706772ed43f389d2ab9b381ef8ec/content.htm?frameset=/en/5d/a591c5a5a54740948acfe56b22fbc3/frameset.htm&current_toc=/en/5c/be4e5b4a19479a92b1d32ff23b7b63/plain.htm&node_id=189

編輯:如果這些片段被從兩個不同的視圖中調用,最好使用ID的ID視圖。我將修改代碼以實例如下片段:

var oView = this.getView(); 
this.oAddCustomerDialog = sap.ui.xmlfragment(oView.getId(),"com.sap.lccapp.fragment.AddCustomer", this);