DojoType parsing on AJAX downloadable content

I get an error when parsing checkboxes in a table loaded by AJAX, but I get an error when a widget with this ID is already registered:
"Error (" I tried to register the widget with id == userListUncheckAll, but this identifier is already registered ")"

And I suppose this happens because we pull out the current table and then replace it with what we ever get from an AJAX call, and thus the item id will be the same. Is there a way to "unregister" widgets or something similar?

+4
source share
3 answers

I myself found the answer for this, so I will put it for others:

If you have a set of identifiers that you know should be “unregistered,” create an array of name names:

try { dojo.parser.parse(); } catch (e) { var ids = ['id1', 'id2', 'id3']; dijit.registry.forEach(function(widget) { //remove this check if you want to unregister all widgets if (dojo.indexOf(ids, id) { widget.destroyRecursive(); } }); dojo.parser.parse(); } 

It works like a charm.

+4
source

Get the parent node that you embed in the AJAX content and analyze ONLY this node. You get this error because other widgets in the DOM are processed twice. Something like that:

 require(["dojo/dom", "dojo/parser", "dojo/_base/xhr"/*, etc */ ], function(dom, parser, xhr) { var request = xhr.get({ // your details here }); request.then(function(data) { // transform data if necessary var parentNode = dom.byId("/* parent id */"); parentNode.innerHTML = data; // This is where the widgets get built! parser.parse(parentNode); // or parser.parse("/* parent id */"); }, function(err) { // handle error }); }); 

Also, make sure you include the correct dojo / dijit modules. A common mistake is to forget to enable the modules for the widget that you are trying to insert. For example, if you use TabContainer, add "dijit / layout / TabContainer" to the list of required modules.

+1
source

The Dojo Parser documentation includes this snapshot:

 dojo.xhrGet({ url: "widgets.html", load: function(data){ dojo.byId("container").innerHTML = data; dojo.parser.parse("container"); } }) 

I applied in my code and it works fine.

0
source

Source: https://habr.com/ru/post/1301799/


All Articles