Zebra API Doc

zebra.data.TreeModel Class

Tree model class. The class is simple and handy way to keep hierarchical structure.

Constructor

zebra.data.TreeModel

(
  • [r]
)

Parameters:

  • [r] zebra.data.Item | Object optional

    a root item. As the argument you can pass "zebra.data.Item" or a JavaType object. In the second case you can describe the tree as follow:

    // create tree model initialized with tree structure passed as 
    // special formated JavaScript object   
    var tree = new zebra.data.TreeModel({ value:"Root",
                                         kids: [
                                             "Root kid 1",
                                             { 
                                               value: "Root kid 2",
                                               kids:  [ "Kid of kid 2"] 
                                             }
                                         ]});

Methods

add

(
  • to
  • an
)

Add the new item to the tree model as a children element of the given parent item

Parameters:

  • to zebra.data.Item

    a parent item to which the new item has to be added

  • an Object | zebra.data.Item

    item or value of the item to be added to the parent item of the tree model

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:

  • to zebra.data.Item

    a parent item to which the new item has to be inserted

  • an Object | zebra.data.Item

    item or value of the item to be inserted to the parent item

  • i Integer

    a position the new item has to be inserted into the parent item

remove

(
  • item
)

Remove the given item from the tree model

Parameters:

removeKids

(
  • item
)

Remove all children items from the given item of the tree model

Parameters:

  • item zebra.data.Item

    an item from that all children items have to be removed

setValue

(
  • item
  • v
)

Update a value of the given tree model item with the new one

Parameters:

  • item zebra.data.Item

    an item whose value has to be updated

  • v type

    a new item value

Attributes

root

zebra.data.Item readonly

Reference to the tree model root item

Events

itemInserted

Fired when the tree model item has been inserted into the model

tree.bind(function itemInserted(src, item) { ... });

Event Parameters:

itemModified

Fired when the tree model item value has been updated.

tree.bind(function itemModified(src, item) { ... });

Event Parameters:

itemRemoved

Fired when the tree model item has been removed

tree.bind(function itemRemoved(src, item) { ... });

Event Parameters: