gpt4 book ai didi

javascript - Angular : Adding variable into a chain of promises

转载 作者:行者123 更新时间:2023-11-29 19:24:43 25 4
gpt4 key购买 nike

我正在学习 promises 并且正在努力解决以下问题。

本例中运行了三个函数。

//returns an search query in JSON format
filterSearch()

// searches Parse.com and returns an array of values
.then(performSearch)

// I am passing the array of values to exerciseSearch and a another value (term - string)
.then(function(result) {
exerciseSearch(result, term);
})

// The results from the search is displayed in scope.
.then(function(exercises) {
$scope.allExercises = exercises;

}, function(error) {
console.log('error');
});

最佳答案

Promise 链应该总是有来自 .then 的返回对象来继续 promise 链

//returns an search query in JSON format
filterSearch()

// searches Parse.com and returns an array of values
.then(performSearch)

//(term - string)
.then(function(result) {
return exerciseSearch(result, term); //exerciseSearch should return exercises from fn
})

// The results from the search is displayed in scope.
.then(function(exercises) {
$scope.allExercises = exercises;
return exercises;
}, function(error) {
console.log('error');
});

关于javascript - Angular : Adding variable into a chain of promises,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31278764/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com