Working with Trees > Classes > TreeNodes > TreeNodes.updateFrom
updateFrom (jsonData)
jsonData. Array of JSON objects that have fields corresponding to properties of the class PP.Ui.TreeNode.
The updateFrom method inserts an array of tree items to the node deleting all children of the node. It reserves items' state (that is, properties set for these items), initializing them by the key.
The updateFrom method differs from the loadFrom method in the fact that updateFrom inserts elements in the same order as in JSON, and if the keys of the replaced node and the source node match, no node property is changed, except for Text, while loadFrom sets default values for all properties if they are not specified.
To execute this example, the page must contain the TreeList component named treeList (seebsp; Example of Creating the TreeList Component). The newSettings variables contains a JSON object which stores description of component nodes:
NOTE. Set a key for each of the nodes.
var newSettings = [
{
Text: "Node 1",
Columns: ["10", "12", "34"],
Selected: true,
CanSelect: true,
Checked: true,
Key: 10
},
{
Text: "Node 2",
Columns: ["12", "123", "33"],
Selected: false,
CanSelect: true,
Checked: false,
Key: 11
},
{
Text: "Node 3",
Columns: ["33", "67", "65"],
Selected: false,
CanSelect: true,
Checked: true,
Key: 12
}]
Refresh the tree:
treeList.getNodes().updateFrom(newSettings)
After executing the example the tree looks as follows:
See also: