Created
July 6, 2015 15:23
-
-
Save lanegoolsby/fa5b4f84a3194659a309 to your computer and use it in GitHub Desktop.
Simple IIFE promise chain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$scope.loadParents = function () { | |
spService.getParents().then(function (pResult) { | |
for (var x = 0; x < pResult.data.d.results.length; x++) { | |
var iter = pResult.data.d.results[x]; | |
var parent = {}; | |
parent.Title = iter.Title; | |
parent.ChildColumnId = iter.ChildColumnsId; | |
parent.Children = []; | |
$scope.parents.push(parent); | |
} | |
for (var idx in $scope.parents) { | |
(function (idx) { | |
var iter = $scope.parents[idx]; | |
var childPromises = []; | |
childPromises.push(spService.getChildren(iter.ChildColumnId)); | |
$q.all(childPromises).then(function (childResults) { | |
var child = {}; | |
child.Title = childResults[0].data.d.Title; | |
iter.Children.push(child); | |
}); | |
})(idx); | |
} | |
}) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment