JNode
From Joomla! Documentation
(Difference between revisions)
(New page: '''JNode''' is a class that allows you to create nodes, normaly used as "leaves" of object-trees. Often used in conjunction with the JTree class. ===Availability=== {{JVer|1.5|From Jo...) |
|||
| Line 31: | Line 31: | ||
!Method name | !Method name | ||
!Description | !Description | ||
| + | |- | ||
| + | |[[JNode/__construct|__construct]] | ||
| + | |Constructor | ||
| + | |- | ||
| + | |[[JNode/addChild|addChild]] | ||
| + | |Adds a child to the node. Should also be a JNode object. | ||
| + | |- | ||
| + | |[JNode/getChildren/getChildren]] | ||
| + | |Returns array of all Child-Nodes of this node | ||
| + | |- | ||
| + | |[[JNode/hasChildren|hasChildren]] | ||
| + | |Returns true, if this node has children | ||
|} | |} | ||
===Importing=== | ===Importing=== | ||
| Line 39: | Line 51: | ||
* [[JTree]] | * [[JTree]] | ||
<noinclude>[[Category:Development]][[Category:Framework]][[Category:JNode]]</noinclude> | <noinclude>[[Category:Development]][[Category:Framework]][[Category:JNode]]</noinclude> | ||
| + | |||
| + | ==Examples == | ||
| + | |||
| + | JTree and JNode can be used to create and process simple tree structures. Let's see how this works for JNode with a simple example. | ||
| + | |||
| + | We want to create the Family Tree of the Smiths. Granny Barbara has two daughters. Stefanie and Aunti Sue. Stefanie has two children, Peter and Stewie. Auntie Sue doesn't have children. | ||
| + | |||
| + | Let's take a look how we can represent this familiy in an object tree. | ||
| + | <source lang="php"> | ||
| + | $barbara = new JNode(); | ||
| + | $stefanie = new JNode(); | ||
| + | $sue = new JNode(); | ||
| + | $peter = new JNode(); | ||
| + | $stewie = new JNode(); | ||
| + | |||
| + | //Granny Barbara has two children, stefanie, and sue | ||
| + | $barbara->addChild($stefanie); | ||
| + | $barbara->addChild($sue); | ||
| + | |||
| + | /* | ||
| + | * Sometimes we want declare parent-child relationships the other way around. | ||
| + | * We can also do that | ||
| + | */ | ||
| + | |||
| + | $peter->setParent($stefanie); | ||
| + | $stewie->setParent($stefanie); | ||
| + | </source> | ||
Revision as of 06:47, 9 August 2009
JNode is a class that allows you to create nodes, normaly used as "leaves" of object-trees. Often used in conjunction with the JTree class.
Contents |
Availability
Defined in
/libraries/joomla/base/tree.php
Extends
Get and Set Methods
Properties which do not have specific get or set methods listed here can be retrieved or set using the inherited JObject->get method.
| Get method | Set method | Description | Property |
|---|---|---|---|
| getParent | setParent | Gets/Sets the parent of the Node. The parent should also be a JNode object. | $_parent
|
Other Methods
| Method name | Description |
|---|---|
| __construct | Constructor |
| addChild | Adds a child to the node. Should also be a JNode object. |
| [JNode/getChildren/getChildren]] | Returns array of all Child-Nodes of this node |
| hasChildren | Returns true, if this node has children |
Importing
jimport( 'joomla.base.tree' );
See also
Examples
JTree and JNode can be used to create and process simple tree structures. Let's see how this works for JNode with a simple example.
We want to create the Family Tree of the Smiths. Granny Barbara has two daughters. Stefanie and Aunti Sue. Stefanie has two children, Peter and Stewie. Auntie Sue doesn't have children.
Let's take a look how we can represent this familiy in an object tree.
$barbara = new JNode(); $stefanie = new JNode(); $sue = new JNode(); $peter = new JNode(); $stewie = new JNode(); //Granny Barbara has two children, stefanie, and sue $barbara->addChild($stefanie); $barbara->addChild($sue); /* * Sometimes we want declare parent-child relationships the other way around. * We can also do that */ $peter->setParent($stefanie); $stewie->setParent($stefanie);