API16

Difference between revisions of "JNode"

From Joomla! Documentation

(New page: <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>Edit Descripton<nowiki>]</nowiki> </span> {{Description:JNode}} ===Defined in=== libraries...)
 
(Fix broken examples section)
Line 45: Line 45:
 
<dpl>
 
<dpl>
 
  noresultsheader=\n
 
  noresultsheader=\n
 +
namespace=CodeExample
 
  category=JNode
 
  category=JNode
 
  category=CodeExample
 
  category=CodeExample
Line 50: Line 51:
 
  include=*
 
  include=*
 
  format= ,,,
 
  format= ,,,
 +
reset=categories
 
</dpl>
 
</dpl>

Revision as of 03:06, 10 July 2013

The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

[Edit Descripton] Template:Description:JNode

Defined in[edit]

libraries/joomla/base/node.php

Methods[edit]

Method name Description
__construct Constructor
addChild Add child to this node
setParent Set the parent of a this node
getChildren Get the children of this node
getParent Get the parent of this node
hasChildren Test if this node has children
hasParent Test if this node has a parent

Importing[edit]

jimport( 'joomla.base.node' );

[Edit See Also] Template:SeeAlso:JNode

Examples[edit]

<CodeExamplesForm />

Tree Structures with JNode

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 represent the family structure 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);
Batch1211 19:48, 22 March 2010 (EDT) Edit comment