‎2019 May 07 10:03 AM
Hello,
Im facing a small issue to remove an object from nested json array which will get generated dynamically. Below is the json..
Actually my requirement is like, I have a JSON Tree, and user can add or delete multiple nodes..
[{
"mainTxt": "test",
"subTxt": "SubTxt1",
"nodes": [{
"mainTxt": "test",
"subTxt": "SubTxt2",
"nodes": [{
"mainTxt": "test",
"subTxt": "test Operations",
"nodes": [{
"mainTxt": "test",
"subTxt": "test Operations",
"nodes": [{
"mainTxt": "test",
"subTxt": "test Operations"
}]
}]
}]
}, {
"mainTxt": "test",
"subTxt": "SubTxt3",
"nodes": [{
"mainTxt": "test",
"subTxt": "test Operations",
"nodes": [{
"mainTxt": "test",
"subTxt": "test Operations"
}]
}]
}, {
"mainTxt": "test",
"subTxt": "india"
}, {
"mainTxt": "test",
"subTxt": "SubTxt4"
}, {
"mainTxt": "test",
"subTxt": "SubTxt5"
}]
}]
Here the below code blocks may get added or removed dynamically
"nodes": [{
"mainTxt": "test",
"subTxt": "test Operations"
}]
and
{
"mainTxt": "test",
"subTxt": "SubTxt5"
}
How can i remove above blocks which got added dynamically and after removing again i need to form the same JSON array.
I tried multiple ways in writing a loop by finding index of that particular object in array and tried to remove using splice() and delete() method. But it didn't worked properly.
Can someone please help me if there is any simple fix?
Thank you in advance..
‎2019 May 07 4:22 PM
Fixed the issue with below Code..
removeTile:function(oEvt){
this._deleteRecord(globalArray, selObject);
_oModel.setData(oModelData);},
_deleteRecord:function(items, record){if(items !== undefined){for(var i=0;i< items.length;i++){if(items[i]=== record){
items.splice(i,1);break;}else{
this._deleteRecord(items[i].nodes, record);}}}}