im working on django rest and angular this json array is comming from server ic contain category and subCategory values..
im trying to build a dynamic navbar so i want to arrange this data like
[
[web development] : ["subCat1","subcat2",....]
[android development] : ["subCat1","subcat2",....]
]
to access category and its related subctegory
i tried somthing like this : but it set only keys and value are empety
public categories = [[], [], [], []];
public data;
for (let i = 0; i < this.data.length; i++) {
if (this.data[i].cat_id != null) {
this.categories[i][this.data[i].title] = [];
}
if (this.data[i].parent_id != null && this.data[i].parent_id == this.data[i].cat_id) {
this.categories[i][this.data[i].title] = [this.data[i].title]
}
}
its server response
[
{
"id": 5,
"cat_id": 0,
"parent_id": null,
"title": "web development"
},
{
"id": 6,
"cat_id": 1,
"parent_id": null,
"title": "android development"
},
{
"id": 7,
"cat_id": null,
"parent_id": 0,
"title": "php"
},
{
"id": 8,
"cat_id": null,
"parent_id": 1,
"title": "java"
}
]