Sapui5 在不同控制器中创建片段时出现重复ID错误
所以。。。我正在构建一个基本上是CRUD的应用程序。在这个应用程序中,我有以下视图/控制器:VisitEdit和RequestNew 在RequestNew控制器上,我有一个处理按钮按下的功能:Sapui5 在不同控制器中创建片段时出现重复ID错误,sapui5,Sapui5,所以。。。我正在构建一个基本上是CRUD的应用程序。在这个应用程序中,我有以下视图/控制器:VisitEdit和RequestNew 在RequestNew控制器上,我有一个处理按钮按下的功能: onRequestNewAddCustomerPress: function(oEvent) { if( !this.oAddCustomerDialog ){ this.oAddCustomerDialog = sap.ui.xmlfragment("com.sap.lccapp.frag
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控制器上,当我第二次尝试使用与上述相同的代码使用相同的对话框时,它显示以下错误: 正在添加具有重复id“addCustomerNameField”的元素 ID
“addCustomerNameField”
来自片段中的第一个元素
虽然我在这两种方法上都有“如果验证”,而且因为它在不同的控制器中,最后一个被验证的“如果”对象(this.oAddCustomerDialog
)未定义(但它不应该有未定义的值),并且它正在再次创建sap.ui.xmlfragment
片段定义:在实例化片段时,可以关联唯一的ID。这样,该唯一ID将作为片段包含的控件ID的前缀 因此,将使用两种不同的代码: onRequestNewAddCustomerPress:函数(oEvent){ 如果(!this.oAddCustomerDialog){ this.oAddCustomerDialog=sap.ui.xmlfragment(“idonnerRequest”、“com.sap.lccapp.fragment.AddCustomer”,this); } openBy(oEvent.getSource()); }, 然后:
OnVisitedItadCustomerPress:函数(oEvent){
如果(!this.oAddCustomerDialog){
this.oAddCustomerDialog=sap.ui.xmlfragment(“idOnEdit”、“com.sap.lccapp.fragment.AddCustomer”,this);
}
openBy(oEvent.getSource());
},
此外,请检查以下文档主题:
编辑:如果从两个不同的视图调用这些片段,最好使用视图的ID。我将修改代码以实例化片段,如下所示:
this.oAddCustomerDialog=sap.ui.xmlfragment(this.getView().getId(),“com.sap.lccapp.fragment.AddCustomer”,this);
从UI5 1.58开始,工厂函数
sap.ui.*fragment
已被弃用。请改用
Fragment.load({
id:this.getView().getId(),
名称:“com.sap.lccapp.fragment.AddCustomer”,
控制员:这个,
}); // 回报承诺