如何通过ID注册但不在任何DOM节点中引用来删除dojo小部件 [英] How to remove dojo widgets by registered by id, but not referenced in any DOM node

查看:142
本文介绍了如何通过ID注册但不在任何DOM节点中引用来删除dojo小部件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上下文:我正在处理一个已经转换为单页面应用程序的应用程序。应用程序中有很多小部件,其中很多都被分配了id,因此在需要时可以轻松获取。当我们在应用程序中导航时,domNode将被 domConstruct.empty(this.someNode)清除,并且正在放置新的DOM。



这里发生的问题是,虽然DOM被清除,但是小部件仍然被相同的ids注册,当我们再次导航到该页面时,它只显示任何内容。 (甚至没有例外,在Chrome,Firefox,IE中尝试)



以前工作正常,因为在导航期间,每次打开一个新页面新链接,因此没有与ids相关的问题。



那么,如何删除ids所注册但不被任何domNode引用的小部件? p>

PS:我知道问题与窗口小部件的ids相关,因为当我只注册了一个带有ID的窗口小部件时,它首次注册,但是当我导航再次在调试时,在该步骤,小部件没有注册,也没有例外。



Edit1:是否使用this.own()一个解决方案?

解决方案

在面值,你正在寻找 dijit / registry.findWidgets

  require(['dojo / _base / array','dojo / dom-construct','dijit / registry'],function(arrayUtil,domConstruct,registry){
arrayUtil.forEach (registry.findWidgets(this.someNode),function(widget){
widget.destroyRecursive();
});
domConstruct.empty(this.someNode);
});

如果您通常需要处理通常需要清除的自由格式内容区域,刷新,您可能需要查看 dijit / layout / ContentPane


Context: I am working on an application which has now been converted to a single page application. There are many widgets in the application and a lot of them have been assigned id, so that they are easy to get as and when required. When we navigate inside the application, the domNode is being cleared by domConstruct.empty(this.someNode) and new DOM is being placed in it.

The problem happening here is, although the DOM is cleared, but the widgets are still registered by the same ids and when we navigate to that page again, it just shows up nothing. (There is not even an exception. Tried in Chrome, Firefox, IE)

It was working fine previously, because during navigation, every time a new page opened up with a new link, hence there was no problem related to ids.

So, how can I remove the widgets that are registered by ids but are not referenced by any domNode?

P.S: I know that the problem is related to ids of the widgets because when I registered only a single widget with an id, it got registered for the first time but when I navigated again there while debugging, at that step, the widget did not register and there was no exception either.

Edit1: Is using this.own() a solution for this?

解决方案

At face value, you are looking for dijit/registry.findWidgets:

require([ 'dojo/_base/array', 'dojo/dom-construct', 'dijit/registry' ], function (arrayUtil, domConstruct, registry) {
    arrayUtil.forEach(registry.findWidgets(this.someNode), function (widget) {
        widget.destroyRecursive();
    });
    domConstruct.empty(this.someNode);
});

If you're generally dealing with an area of free-form content that often needs to be cleared or refreshed, you might want to look at dijit/layout/ContentPane.

这篇关于如何通过ID注册但不在任何DOM节点中引用来删除dojo小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆