Parent-Child Relationships with _Container and _Contained
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.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access