items([index], [items_or_recursive])

Class: Tree.

Description:

Sets or gets a list of items for a node at specified index. Setting the list of items will replace current items at specified index before adding new ones. To simply remove existing items pass an empty array as a second parameter.

Parameters:

Name Type Default Description

[index]

Array.<number>

[0]

Index of target item. Default is [0] tree root node

[items_or_recursive]

boolean | Array.<object>

false

To set items, pass an array of items, or empty array to simply remove all items. When getting items you can specify a boolean whether to get all children items recursively or not. Default is false.

Returns:

If setting items then this Tree component is returned. If getting items then Array of items is returned, or undefined if index doesn't point to an item in the Tree.

Type: Array.<object> | undefined | Tree

Examples:

Set items at the root node:

tree.items([0], [
  { text: "Videos", id: 1, icon: "icons/folder-videos.png" },
  { text: "Photos", id: 2, icon: "icons/folder-images.png" }
]);

Set items at a child node:

tree.items([0,0], [
  { text: "Video 1", id: "a1", value: "video1.mp4" },
  { text: "Video 2", id: "a2", value: "video2.mp4", tooltip: "Second video" }
]);

Get direct children of a node:

const rootItems = tree.items([0]);
console.log(rootItems); // → [ {text: "Videos", id: 1, ...}, {text: "Photos", id: 2, ...} ]

Get items recursively from a node:

const deepItems = tree.items([0,0], true);
console.log(deepItems); // → [ {text: "Video 1", id: "a1", ...}, {text: "Video 2", id: "a2", ...} ]

Get from a non-existing index:

const nothing = tree.items([9]);
console.log(nothing); // → undefined