【发布时间】:2014-09-17 17:54:38
【问题描述】:
我试图弄清楚是否有任何方法可以将索引参数传递给 Promise 的回调函数。例如。
serviceCall.$promise.then(function(object){
$scope.object = object;
});
现在我想传入一个数组索引参数为
serviceCall.$promise.then(function(object,i){
$scope.object[i] = something;
});
这可以吗?请告诉我。
下面是代码
StudyService.studies.get({id:
$routeParams.studyIdentifier}).$promise.then(function(study) {
$scope.study = study;
for(var i=0;i<study.cases.length;i++){
StudyService.executionsteps.get({id:
$routeParams.studyIdentifier,caseId:study.cases[i].id})
.$promise.then(function(executionSteps,i){
$scope.study.cases[i].executionSteps = executionSteps;
});
}
});
【问题讨论】:
-
Object 只是另一个名为 Study 的类,其中包含一个案例列表,每个案例都有一个步骤列表。所以我需要能够在回调函数内部建立索引。
-
你从哪里得到
i? -
请看我刚刚在我的问题中添加的代码。
标签: javascript angularjs promise callback