{"_id":"598622fbd09433000f1b97f5","category":{"_id":"598622f9d09433000f1b97e0","version":"598622f9d09433000f1b97dd","project":"5707c6875309d117006948d4","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-04-08T14:56:07.661Z","from_sync":false,"order":2,"slug":"documentation","title":"Guides"},"project":"5707c6875309d117006948d4","parentDoc":null,"user":"54d742a80771980d0052f4b5","version":{"_id":"598622f9d09433000f1b97dd","project":"5707c6875309d117006948d4","__v":1,"createdAt":"2017-08-05T19:56:41.267Z","releaseDate":"2017-08-05T19:56:41.267Z","categories":["598622f9d09433000f1b97de","598622f9d09433000f1b97df","598622f9d09433000f1b97e0","598622f9d09433000f1b97e1"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"4.1.0","version":"4.1.0"},"__v":0,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2017-02-15T13:25:34.307Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":12,"body":"The tree allows to load children asynchronously using `getChildren` option, and `hasChildren` field on the node.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"'getChildren' option:\"\n}\n[/block]\nThis options receives a function that has a TreeNode parameter, and returns a value or a promise that resolves to the node's children:\n```\n(node:TreeNode) => TreeNode[] | Promise<TreeNode[]>\n```\n\nThe function will be called whenever a node is expanded, the `hasChildren` field is true, and the `children` field is empty.\nThe result will be loaded into the node's children attribute.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Example:\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"options = {\\n  getChildren: (node:TreeNode) => {\\n    return request('/api/children/' + node.id);\\n  }\\n}\\n\\nnodes = [\\n  {\\n    name: 'asyncRoot',\\n    hasChildren: true\\n  },\\n  {\\n    name: 'root2',\\n    children: [\\n      {\\n        name: 'leaf',\\n        hasChildren: false\\n      }\\n    ]\\n  }\\n]\\n\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"async-data-1","type":"basic","title":"Async Data"}
The tree allows to load children asynchronously using `getChildren` option, and `hasChildren` field on the node. [block:api-header] { "type": "basic", "title": "'getChildren' option:" } [/block] This options receives a function that has a TreeNode parameter, and returns a value or a promise that resolves to the node's children: ``` (node:TreeNode) => TreeNode[] | Promise<TreeNode[]> ``` The function will be called whenever a node is expanded, the `hasChildren` field is true, and the `children` field is empty. The result will be loaded into the node's children attribute. [block:api-header] { "type": "basic", "title": "Example:" } [/block] [block:code] { "codes": [ { "code": "options = {\n getChildren: (node:TreeNode) => {\n return request('/api/children/' + node.id);\n }\n}\n\nnodes = [\n {\n name: 'asyncRoot',\n hasChildren: true\n },\n {\n name: 'root2',\n children: [\n {\n name: 'leaf',\n hasChildren: false\n }\n ]\n }\n]\n", "language": "javascript" } ] } [/block]