【问题标题】:Dojo destroy MenuItems on DropDownButtonDojo 销毁 DropDownButton 上的 MenuItems
【发布时间】:2013-12-04 12:53:00
【问题描述】:

我有以下标记:

<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));

我也尝试过让标签菜单清空它,但没有运气。有没有其他方法可以在重新加载数据或丢失某些内容时摆脱所有孩子?

【问题讨论】:

    标签: javascript dojo


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      在您的代码中,您在标签上调用 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");
      });
      

      【讨论】:

      • 如果您阅读代码后的行,我已经尝试过了,但它不起作用。
      • 你做到了。对不起,我错过了。以为我在做某事。
      猜你喜欢
      • 1970-01-01
      • 2011-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-15
      • 1970-01-01
      • 1970-01-01
      • 2012-02-18
      相关资源
      最近更新 更多