|
|
| (4 intermediate revisions by one user not shown) |
| Line 1: |
Line 1: |
| − | '''JTree''' is a class that allows you to create and walk through object-trees. Used in conjunction with the [[JNode]] class.
| + | This class is available in the following Joomla versions:- |
| − | | + | <splist showpath=notparent /> |
| − | ===Availability===
| + | <noinclude>[[Category:Platform JClasses]][[Category:JTree]]</noinclude> |
| − | {{JVer|1.5|From Joomla 1.5}} {{JVer|1.6|Joomla 1.6}}
| + | |
| − | | + | |
| − | ===Defined in===
| + | |
| − | /libraries/joomla/base/tree.php
| + | |
| − | | + | |
| − | ===Extends===
| + | |
| − | * [[JObject]]
| + | |
| − | | + | |
| − | ===Methods===
| + | |
| − | {| class="wikitable"
| + | |
| − | |-
| + | |
| − | !Method name
| + | |
| − | !Description
| + | |
| − | |-
| + | |
| − | |[[JTree/__construct|__construct]]
| + | |
| − | |Constructor. Creates the Tree and a Root-Node. Sets the internal pointer to the root-node.
| + | |
| − | |-
| + | |
| − | |[[JTree/addChild|addChild]]
| + | |
| − | |Adds a child node to the node the internal pointer points to.
| + | |
| − | |-
| + | |
| − | |[[JTree/getParent|getParent]]
| + | |
| − | |Sets the internal pointer to the parent node of the current node.
| + | |
| − | |-
| + | |
| − | |[[JTree/reset|reset]]
| + | |
| − | |Resets the internal pointer to the Root-Node.
| + | |
| − | |}
| + | |
| − | ===Importing===
| + | |
| − | <source lang="php">jimport( 'joomla.base.tree' );</source> | + | |
| − | | + | |
| − | ===See also===
| + | |
| − | * [http://api.joomla.org/Joomla-Framework/Base/JTree.html JTree on api.joomla.org]
| + | |
| − | * [[JNode]]
| + | |
| − | <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 JTree 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();
| + | |
| − | | + | |
| − | $familyTree = new JTree(); //pointer set to root-node
| + | |
| − | $familyTree->addChild($barbara, true) //pointer set to barbara
| + | |
| − | $familyTree->addChild($sue) //$sue added as child to barbara, pointer still on barbara
| + | |
| − | $familyTree->addChild($stefanie, true) //$stefanie added as child to barbara, pointer on stefanie
| + | |
| − | $familyTree->addChild($peter, true) //$peter added as child to stefanie, pointer on peter
| + | |
| − | $familyTree->getParent() // pointer set to parent of peter, which is stefanie
| + | |
| − | $familyTree->addChild($stewie) //$stewie added as child to stefanie, pointer on stefanie
| + | |
| − | </source>
| + | |