Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

How to remove all children from tree jQuery

I am using data json. I want to remove all child-parent from array this data json. Want to remove a-A! and A2 and B but remove all child except Child A2

name       parentid     id 
A            0         369
  -A1       369        370  
  -A2       369        371
  -- B      371        372

This use my code

 function removechildtree(roleId)
     {
         $.each(roleArray.filter(function (value1) { return value1.parentId == roleId }), function (index1, child1) {
         if(roleArray.filter(function (value) { return value.parentId == child1.roleId }).length > 0)
         removechildtree(child1.roleId);
         else
         $.each(roleArray.filter(function (value2) { return value2.roleId == child1.roleId }),function (index2, child2) { roleArray.splice($.inArray(child2,roleArray), 1);
     });
})

Comments