public localData: Object[] = [
{
uuid: "1",
name: "Lampung",
hasChild: true
},
{
uuid: "1_1",
parent_id: "1",
name: "Lampung Utara"
},
{
uuid: "1_2",
parent_id: "1",
name: "Lampung Selatan"
},
{
uuid: "2",
name: "Jakarta",
hasChild: true
},
{
uuid: "2_1",
parent_id: "2",
name: "Jakarta Selatan",
hasChild: true
},
{
uuid: "2_1_1",
parent_id: "2_1",
name: "Kemang"
},
{
uuid: "2_2",
parent_id: "2",
name: "Jakarta Utara"
}
]; |
default.html
<ejs-treeview #treeviewObj id="default" [loadOnDemand]=false [showCheckBox]=true [fields]='field' (dataBound)="dataBounded($event)" (nodeChecked)="nodeCheck($event)">
default.components.ts
//Change the dataSource for TreeView
changeDataSource(data) {
for (let i = 0; i < data.length; i++) {
let dataId = data[i]["uuid"].toString();
if (
this.listTreeObj.checkedNodes.indexOf(dataId) !== -1 &&
this.checkNodes.indexOf(dataId) === -1 && !data[i].hasChild
)
this.checkNodes.push(dataId);
}
this.listTreeObj.fields = {
dataSource: data,
id: "uuid",
text: "name",
parentID: "parent_id",
hasChildren: "hasChild"
};
} |