How can I wait at the desired place in the code until all the processing on treeData
is finished?
var treeData = $scope.rawData;
if ($scope.treeExpanded) {
//expand tree
if (treeData && treeData.children) {
treeData.children.forEach(toggleAll);
}
//how to wait here until all recursion calls are finished?
//console.log(treeData) will show a non modified object equals to $scope.rawData
}
function toggle(d) {
if (d.children) {
d._children = d.children;
d.children = null;
}
}
function toggleAll(d) {
if (d && d.children) {
d.children.forEach(toggleAll);
toggle(d);
}
}
toggleAll()
. Which function should I give the callback and when should I execute the callback?