Created
July 6, 2015 15:25
-
-
Save lanegoolsby/eb75d362351e073604c8 to your computer and use it in GitHub Desktop.
More detailed IIFE 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.loadFields = function () { | |
spService.getListSchema('Parent').then(function (fResult) { | |
for (var x = 0; x < fResult.data.d.results.length; x++) { | |
var iter = fResult.data.d.results[x]; | |
if (iter.TypeAsString === "Lookup" && iter.LookupList.indexOf("{") > -1) { | |
iter.LookupList = iter.LookupList.replace("{", "").replace("}", "") | |
$scope.parentLookups.push(iter); | |
} | |
} | |
spService.getParents().then(function (pResult) { | |
$scope.parents = pResult.data.d.results; | |
for (var pIdx in $scope.parents) { | |
(function (pIdx) { | |
var parent = $scope.parents[pIdx]; | |
var fieldReference = []; | |
var promiseChain = []; | |
for (var fIdx in $scope.parentLookups) { | |
var field = $scope.parentLookups[fIdx]; | |
promiseChain.push(spService.getListItemById(field.LookupList, parent[field.EntityPropertyName + "Id"])); | |
fieldReference.push(field.Title); | |
} | |
$q.all(promiseChain).then(function (results) { | |
for (var rIdx in results) { | |
var result = results[rIdx].data.d; | |
parent[fieldReference[rIdx]] = result.Title; | |
} | |
}) | |
})(pIdx); | |
} | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment