我已经阅读了许多关于销毁片段或页面以避免重复ID的帖子,但问题是视图页面中显示了一个片段,当我再次按下相同的按钮时,我得到错误重复ID。< / p>
以下是片段和控制器的代码:
<core:FragmentDefinition xmlns="sap.m"
xmlns:f="sap.ui.layout.form" xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc"
xmlns:html="http://www.w3.org/1999/xhtml" xmlns:l="sap.ui.layout">
<Page id="masterAp" showHeader="false" enableScrolling="true" >
<TileContainer
id="getTiles"
tiles="{myModel1>/0/TileCollection}">
<StandardTile
title="{myModel1>title}"
icon="{myModel1>icon}"
number="{myModel1>number}"
numberUnit="{myModel1>numberUnit}"
info="{myModel1>info}"
infoState="{myModel1>infoState}"
press="handleTilePress"/>
</TileContainer>
</Page>
</core:FragmentDefinition>
控制器的代码:请建议缺少哪些代码行以避免重复ID错误:未捕获错误:错误:添加具有重复ID的元素&#39; getTiles&#39;
onPressGoToMaster1 : function() {
var oDialogFragment = sap.ui.xmlfragment("yca_web111_dashboard.fragments.panel2",this.getView().getController());
var oModel = new sap.ui.model.json.JSONModel("data/dataAP.json");
sap.ui.getCore().setModel(oModel, "myModel1");
var oPage = this.getView().byId("detail");
oPage.insertContent(oDialogFragment);
this.getSplitAppObj().to(this.createId("detail"));
};
答案 0 :(得分:4)
每次移动到带有id:detail的页面时,您都会尝试添加片段。最简单的解决方案是检查您是否已添加片段。
代码:
onPressGoToMaster1 : function() {
if (!this.oDialogFragment) {
this.oDialogFragment = sap.ui.xmlfragment("yca_web111_dashboard.fragments.panel2",this.getView().getController());
var oModel = new sap.ui.model.json.JSONModel("data/dataAP.json");
sap.ui.getCore().setModel(oModel, "myModel1");
var oPage = this.getView().byId("detail");
oPage.insertContent(this.oDialogFragment);
}
this.getSplitAppObj().to(this.createId("detail"));
};