DOJO和DIJIT不能两次分析相同的ID? [英] DOJO and DIJIT can not parse same ID twice?

查看:166
本文介绍了DOJO和DIJIT不能两次分析相同的ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用DOJO时遇到问题,在这里我会动态地加载一些内容的div,然后运行parser.parse(dom.byId(mainDiv));与各自的要求。而且第一次美妙地工作。然而,第二次,我最终遇到一个问题,它只显示内容不再被激活或风格。



在第二次运行我做的是删除所有的HTML在div中,然后用基本的未解析文本替换html,然后再次解析。现在我猜测它必须用dijit.registry做一些事情,但是我找不到确切的问题,因为我已经尝试清除这一点,也没有效果。您的帮助将不胜感激。

解决方案

Dojo会跟踪指定ID所创建的对象/小部件。如果你在同一个id的对象上再次运行解析器,dojo会尝试创建一个第二个实例,但是已经有一个实例,所以应该在你的js控制台中抛出一个错误(请检查)。



您可以将该ID留空,然后dojo / parse应为您创建一个ID。
Dojo允许您通过类属性找到dom元素,这样就可以将div元素传递给parse()函数,而不给它一个明确的id。



另一方面是在再次解析div元素之前,摧毁创建的小部件/对象,看看这里:



取消注册小部件



http://livedocs.dojotoolkit.org/dojo/parser#parse


如果您尝试解析相同的内容两次,或解析内容
提及现有的小部件的ID,它将导致一个关于
重复ID的



I am having a problem while working with DOJO where I will dynamically load a div with some content and then run parser.parse(dom.byId("mainDiv")); with the respective requires. And that works beautifully the first time. The second time however I end up running into a problem where it just shows the content no longer activated or styled.

On a second run what I do is remove all the html in the div and then replace the html with basic unparsed text and then I parse it again. Now I am guessing it has to do something with dijit.registry however I can not find exactly what the issue is as I have tried clearing that out as well to no avail. Your help would be much appreciated.

解决方案

Dojo keeps track of the objects / widgets it creates by the specified id. If you run the parser again on an object with the same id, dojo tries to create a second instance, but there is already one, so it should throw an error in your js console (please check).

You could leave the id blank, then dojo / parse should create an id for you. Dojo allows you to find dom elements by class attributes, that way you could pass your div-element to the parse() function without giving it an explicit id.

Anotherway would be to destroy the created widget/object before you parse the div-element again, take a look here for that:

Dojo and unregistering widgets

Quote from http://livedocs.dojotoolkit.org/dojo/parser#parse

"If you try to parse the same content twice, or parse content mentioning id's of existing widgets, it will cause an exception about duplicate id's"

这篇关于DOJO和DIJIT不能两次分析相同的ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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