Ray Wadkins
Ray Wadkins

Reputation: 904

Finding child nodes of a module using Dojo parser

We use dojo/parser on our application to parse html produced by our server side templating language using the dojo-data-type attribute.

One common thing we need to do is access a node that's part of the modules' domNode to do something with. We've come up with a unique id method for id'ing the nodes we want, but that leaves me uneasy for various reasons.

the _templated mixin allows you to define 'attach-points' in templates that get attached to the object instance. Does something like this exist for for the parser, so a node can be easily identified by the module code?

If not, what's the best way to parse the module's domNode to find these important child nodes, especially avoiding child nodes that belong to another (child) module's domNode?

Upvotes: 0

Views: 179

Answers (1)

mwilcox
mwilcox

Reputation: 4132

No, attach-point is not supported in the parser. That is a Dijit template thing.

Using an ID will work, but that runs the risk of duplicate IDs and things will break. I'd suggest using classNames and finding your nodes with dojo.query.

If the attachable items are other Dijits, you can access them with widget.getChildren();

If you are not using all the features of dojo.parser (there a lot that I don't use) you could build your own. I built one, and it's shocking how tiny it is compared to Dojo's. Note that mine has just been created and has had very little testing, so this is just for reference. https://github.com/clubajax/dx-ui/blob/master/util/parser.js

Upvotes: 1

Related Questions