Class
zebkit.data.TreeModel
mixed with <zebkit.data.DataModel> <zebkit.EventProducer> |
<zebkit.data> |
Tree model class. The class is simple and handy way to keep hierarchical structure.
zebkit.data.TreeModel
([r]
)
Parameters:
-
[r]
<zebkit.data.Item | Object>a root item. As the argument you can pass "zebkit.data.Item" or a JavaScript object. In the second case you can describe the tree as it is shown in example below:
Example:
// create tree model initialized with tree structure passed as
// special formated JavaScript object. The tree will look as follow:
// "Root"
// |
// +--- "Root kid 1"
// +--- "Root kid 2"
// |
// +--- "Kid of kid 2"
var tree = new zebkit.data.TreeModel({
value:"Root",
kids: [
"Root kid 1",
{
value: "Root kid 2",
kids: [ "Kid of kid 2"]
}
]
});
...
// reg item modified events handler
tree.on("itemModified", function(tree, item, prevValue) {
// catch item value modification
...
});
// item value has to be updated via tree model API
tree.setValue(tree.root.kids[0], "new value");
public | void | add ([to], an) |
public static | <zebkit.data.Item> | create (r) |
public static | <Array> | find (root, value, [cb]) |
public static | <zebkit.data.Item> | findOne (root, value) |
public | void | insert (to, an, i) |
public | void | iterate (r, f) |
public | void | remove (item) |
public | void | removeKids (item) |
public | void | setValue (item, v) |
public
void
add ([to], an )
Add the new item to the tree model as a children element of the given parent item Parameters:
|
public
static
<zebkit.data.Item>
create (r )
Create tree model item hierarchy by the given JavaScript object. Parameters:
Returns:
<zebkit.data.Item>
a built items hierarchy Example:
|
public
static
<Array>
find (root, value, [cb] )
Find all items (starting from the specified root item) whose value equals the given value. Parameters:
Returns:
<Array>
a list of all found item whose value matches the specified one. The array is returned only if no callback method has been passed to the method. Example:
|
public
static
<zebkit.data.Item>
findOne (root, value )
Find the first tree item (starting from the specified root item) whose value equals the given value. Parameters:
Returns:
<zebkit.data.Item>
a found tree item |
public
void
insert (to, an, i )
Insert the new item to the tree model as a children element at the given position of the parent element Parameters:
|
public
void
iterate (r, f )
Iterate over tree hierarchy starting from its root element Parameters:
|
public
void
remove (item )
Remove the given item from the tree model Parameters:
|
public
void
removeKids (item )
Remove all children items from the given item of the tree model Parameters:
|
public
void
setValue (item, v )
Update a value of the given tree model item with the new one Parameters:
|
itemInserted
Fired when the tree model item has been inserted into the model
Parameters:
|
itemModified
Fired when the tree model item value has been updated.
Parameters:
|
itemRemoved
Fired when the tree model item has been removed
Parameters:
|