I'm working with AngularJS and have an object array like that in my controller :
$scope.folderList = [{
name: 'root',
path: 'uploads/',
subs: [{
name: 'pictures',
path: 'uploads/pictures',
subs: [{
...
}]
}, {
name: 'videos',
path: 'uploads/videos',
subs: [{
...
}]
}]
}];
For this nested array, I have 2 directives set them up in a nested UL LI list with ng-repeat.
Now I have my nested list of folders, and I want to trigger a function to delete the selected folder.
So I trigger my function to delete with "folder" in parameter, for example, if I trigger the "delete" function on the pictures folder, the folder parameter will be like that :
folder = {
name: 'pictures',
path: 'uploads/pictures',
subs: [{ ... }]
}
And I want to delete this object from the nested array.
With a 1 level object array, I use this :
var index = $scope.folderList.indexOf(folder);
delete $scope.folderList.splice(index, 1);
But it (obviously) doesn't work on a nested array !
How can I easily delete an entry from a nested array on JavaScript (or AngularJS ?)
I've heard that underscore.js was made for this, but I never used it, and after seeing their documentation I wasn't able to find the proper function to do this !
Thanks for your help !
subs
for this. You may also need to think how you'll perform your compare if the search parameterfolder
is an identical Object but not the same reference. – Paul S. Sep 2 '13 at 11:42this
to call it onvar cd = $scope.folderList; cd = cd[0]; cd.splice(0, 1);
– Paul S. Sep 2 '13 at 12:02