angular ngx-tree view data format




Asked on April 23, 2018
Hello,

I am referring the following document
https://github.com/leovo2708/ngx-treeview/tree/master/src/demo/book

For the above link i need to fetch data as below
const itCategory = new TreeviewItem({
text: 'IT', value: 9, children: [
{
text: 'Programming', value: 91, children: [{
text: 'Frontend', value: 911, children: [
{ text: 'Angular 1', value: 9111 },
{ text: 'Angular 2', value: 9112 },
{ text: 'ReactJS', value: 9113, disabled: true }
]
}, {
text: 'Backend', value: 912, children: [
{ text: 'C#', value: 9121 },
{ text: 'Java', value: 9122 },
{ text: 'Python', value: 9123, checked: false, disabled: true }
]
}]
},
{
text: 'Networking', value: 92, children: [
{ text: 'Internet', value: 921 },
{ text: 'Security', value: 922 }
]
}
]
});

But from my api i will get data as follows
[{"pk_location_id":1,"locationname":"Oman","parent_location_id":0,"has_children":true},
{"pk_location_id":2,"locationname":"Muscat","parent_location_id":1,"has_children":true},
{"pk_location_id":3,"locationname":"Seeb","parent_location_id":1,"has_children":false},
{"pk_location_id":4,"locationname":"Ruwi","parent_location_id":2,"has_children":false}]

how can i write function for getting data in that format in angular 2/4. Kindly anyone help me out in this

Regards
Amruta 





Replied on March 07, 2019
Please check below link(source code), here they have used custome JSON(source code link & Demo link)
https://github.com/leovo2708/ngx-treeview/tree/master/src/demo/city
https://leovo2708.github.io/ngx-treeview/#/pipe


Write Answer











©2024 concretepage.com | Privacy Policy | Contact Us