DOJO and DIJIT can not parse same ID twice?

為{幸葍}努か 提交于 2019-12-11 17:52:14

问题


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.


回答1:


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"



来源:https://stackoverflow.com/questions/15888832/dojo-and-dijit-can-not-parse-same-id-twice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!