W3cubDocs

/Dojo

dojo/parser

Summary

The Dom/Widget parsing package

See the dojo/parser reference documentation for more information.

Properties

Methods

construct(ctor,node,mixin,options,scripts,inherited)

Defined by dojo/parser

Calls new ctor(params, node), where params is the hash of parameters specified on the node, excluding data-dojo-type and data-dojo-mixins. Does not call startup().

Parameter Type Description
ctor Function

Widget constructor.

node DOMNode

This node will be replaced/attached to by the widget. It also specifies the arguments to pass to ctor.

mixin Object
Optional

Attributes in this object will be passed as parameters to ctor, overriding attributes specified on the node.

options Object
Optional

An options object used to hold kwArgs for instantiation. See parse.options argument for details.

scripts DomNode[]
Optional

Array of <script type="dojo/*"> DOMNodes. If not specified, will search for <script> tags inside node.

inherited Object
Optional

Settings from dir=rtl or lang=... on a node above this node. Overrides options.inherited.

Returns: any | undefined

Instance or Promise for the instance, if markupFactory() itself returned a promise

instantiate(nodes,mixin,options)

Defined by dojo/parser

Takes array of nodes, and turns them into class instances and potentially calls a startup method to allow them to connect with any children.

Parameter Type Description
nodes Array

Array of DOM nodes

mixin Object
Optional

An object that will be mixed in with each node in the array. Values in the mixin will override values in the node, if they exist.

options Object
Optional

An object used to hold kwArgs for instantiation. See parse.options argument for details.

Returns: any | undefined

Array of instances.

parse(rootNode,options)

Defined by dojo/parser

Scan the DOM for class instances, and instantiate them.

Search specified node (or root node) recursively for class instances, and instantiate them. Searches for either data-dojo-type="Class" or dojoType="Class" where "Class" is a a fully qualified class name, like dijit/form/Button

Using data-dojo-type: Attributes using can be mixed into the parameters used to instantiate the Class by using a data-dojo-props attribute on the node being converted. data-dojo-props should be a string attribute to be converted from JSON.

Using dojoType: Attributes are read from the original domNode and converted to appropriate types by looking up the Class prototype values. This is the default behavior from Dojo 1.0 to Dojo 1.5. dojoType support is deprecated, and will go away in Dojo 2.0.

Parameter Type Description
rootNode DomNode
Optional

A default starting root node from which to start the parsing. Can be omitted, defaulting to the entire document. If omitted, the options object can be passed in this place. If the options object has a rootNode member, that is used.

options Object
Optional

A hash of options.

  • noStart: Boolean?: when set will prevent the parser from calling .startup() when locating the nodes.
  • rootNode: DomNode?: identical to the function's rootNode argument, though allowed to be passed in via this `options object.
  • template: Boolean: If true, ignores ContentPane's stopParser flag and parses contents inside of a ContentPane inside of a template. This allows dojoAttachPoint on widgets/nodes nested inside the ContentPane to work.
  • inherited: Object: Hash possibly containing dir and lang settings to be applied to parsed widgets, unless there's another setting on a sub-node that overrides
  • scope: String: Root for attribute names to search for. If scopeName is dojo, will search for data-dojo-type (or dojoType). For backwards compatibility reasons defaults to dojo._scopeName (which is "dojo" except when multi-version support is used, when it will be something like dojo16, dojo20, etc.)
  • propsThis: Object: If specified, "this" referenced from data-dojo-props will refer to propsThis. Intended for use from the widgets-in-template feature of dijit._WidgetsInTemplateMixin
  • contextRequire: Function: If specified, this require is utilised for looking resolving modules instead of the dojo/parser context require(). Intended for use from the widgets-in-template feature of dijit._WidgetsInTemplateMixin.

Returns: Mixed | Array

Returns a blended object that is an array of the instantiated objects, but also can include a promise that is resolved with the instantiated objects. This is done for backwards compatibility. If the parser auto-requires modules, it will always behave in a promise fashion and parser.parse().then(function(instances){...}) should be used.

Examples

Example 1

Parse all widgets on a page:

parser.parse();

Example 2

Parse all classes within the node with id="foo"

parser.parse(dojo.byId('foo'));

Example 3

Parse all classes in a page, but do not call .startup() on any child

parser.parse({ noStart: true })

Example 4

Parse all classes in a node, but do not call .startup()

parser.parse(someNode, { noStart:true });
// or
parser.parse({ noStart:true, rootNode: someNode });

scan(root,options)

Defined by dojo/parser

Scan a DOM tree and return an array of objects representing the DOMNodes that need to be turned into widgets.

Search specified node (or document root node) recursively for class instances and return an array of objects that represent potential widgets to be instantiated. Searches for either data-dojo-type="MID" or dojoType="MID" where "MID" is a module ID like "dijit/form/Button" or a fully qualified Class name like "dijit/form/Button". If the MID is not currently available, scan will attempt to require() in the module.

See parser.parse() for details of markup.

Parameter Type Description
root DomNode
Optional

A default starting root node from which to start the parsing. Can be omitted, defaulting to the entire document. If omitted, the options object can be passed in this place. If the options object has a rootNode member, that is used.

options Object

a kwArgs options object, see parse() for details

Returns: Promise | undefined

A promise that is resolved with the nodes that have been parsed.

© 2005–2017 JS Foundation
Licensed under the AFL 2.1 and BSD 3-Clause licenses.
http://dojotoolkit.org/api/1.10/dojo/parser.html