DOJO和DIJIT不能两次分析相同的ID? [英] DOJO and DIJIT can not parse same ID twice?
问题描述
在第二次运行我做的是删除所有的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屋!