After you've been rolling with _Widget
and _Templated
for a while, it won't be long
before you find that it's convenient to have a widget that contains
some children widgets. The "has-a relationship" pattern is quite
common in programming and it is no different with Dojo. The _Container
and _Contained
mixins are designed to facilitate
the referencing back and forth between parents and children that often
needs to happen. Table 12-1 summarizes the
API.
Table 12-1. _Container and _Contained mixins
Name | Comment |
---|---|
| Removes the child widget from the parent. (Silently fails if the widget is not a child or if the container does not have any children.) |
| Adds a child widget to
the parent, optionally using the |
| Allows a child to reference its parent. Returns a dijit instance. |
| Allows a parent to
conveniently enumerate each of its children dijits. Returns an
|
| Allows a child widget to reference its previous sibling, i.e., the one "to the left." Returns a dijit instance. |
| Allows a child widget to reference its next sibling, i.e., the one "to the right." Returns a dijit instance. |
You'll see these mixins used extensively when you learn about the layout dijits. Next, we'll look at an example.
Get Dojo: The Definitive Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.