My requirement is, if I select a single category for the subscription on my client side, then I am sending that category details related to that category, and storing those in my backend with some id's and then pushing back to the client side to show those categories in one section to my user. So I will get an array of like below which is coming from my backend DB
[
{
catId:"veg",
catName:"vegetarian",
subCatId:"potato",
subcatName:"potatoes"
},
{
catId:"veg",
catName:"vegetarian",
subCatId:"tomato",
subcatName:"tomatoes"
},
{
catId:"nonveg",
catName:"Non vegetarians",
subCatId:"chicken",
subcatName:"chicken"
},
{
catId:"apetizer",
catName:"Apitizers",
subCatId:"veg-apitizer",
subcatName:"vegetarian Apitizers"
}
]
Now I want the resultant array like as below,
[
{
catId:"veg",
catName:"vegetarian",
subcatsArray:[
{
catId:"veg",
catName:"vegetarian",
subCatId:"potato",
subcatName:"potatoes"
},
{
catId:"veg",
catName:"vegetarian",
subCatId:"tomato",
subcatName:"tomatoes"
}
]
},
{
catId:"nonveg",
catName:"Non vegiterians",
subcatsArray:[
{
catId:"nonveg",
catName:"Non vegiterians",
subCatId:"chicken",
subcatName:"chicken"
}
]
},{
catId:"apetizer",
catName:"Apitizers",
subcatsArray:[
{
catId:"apetizer",
catName:"Apitizers",
subCatId:"veg-apitizer",
subcatName:"vegetarian Apitizers"
}
]
}
]
If again, I am subscribing to another sub-category, then I want to push that sub-category into that related category array of subcatsArray as shown in the model structure above.
Note: I am showing the resultant subscribed categories in another page where as I am subscribing categories, subcategories in separate page
catIdandcatNameinsubcatsArrayas it is just repetition of data.