簡體   English   中英

Dojo破壞DropDownButton上的MenuItem

[英]Dojo destroy MenuItems on DropDownButton

我有以下標記:

<button dojoType="dijit.form.DropDownButton" dojoAttachPoint="labels" label="Labels">
    <div dojoType="dijit.Menu" dojoAttachPoint="labelsMenu"></div>
</button>

我以編程方式添加MenuItems,並且第一次可以正常工作。 但是,當我想刷新時,出現錯誤: Tried to register widget with id==16 but that id is already registered 我已經嘗試清除以下代碼,但無法正常工作:

var labels = dijit.findWidgets(this.labels);
dojo.forEach(labels, function (l) {
    l.destroyRecursive();
});
dojo.empty(dojo.byId(this.labels));

我也嘗試過將labelsMenu清空,但是沒有運氣的方法。 重新加載數據或丟失某些東西時,還有其他方法可以擺脫所有子項嗎?

我已經解決了,這就是我所做的: var menuChildren = dijit.byId(this.labelsMenu).getChildren(); if (menuChildren.length > 0){ dojo.forEach(menuChildren, function(mc){ mc.destroyRecursive(); }); } var menuChildren = dijit.byId(this.labelsMenu).getChildren(); if (menuChildren.length > 0){ dojo.forEach(menuChildren, function(mc){ mc.destroyRecursive(); }); }

在代碼中,您可以在標簽上調用dojo.empty。 dojo.empty()清空DOM中的元素,但保留原始元素。 因此,請嘗試改為在dijit菜單上調用dojo.empty。

dojo.empty(dojo.byId("labelsMenu"));

作為參考,在完全無基礎的應用程序中 ,使用dom-construct模塊。

require(["dojo/dom-construct"], function(domConstruct){
  // Empty node's children byId:
  domConstruct.empty("someId");
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM