請問在文檔裡的 _.each 是什麼意思? 謝謝。
https://cn.avoscloud.com/docs/js_guide.html#promise
順序的 Promise
在你想要某一行數據做一系列的任務的時候,Promise 鏈是很方便的, 每一個任務都等著前 一個任務結束. 比如, 假設你想要刪除你的 blog 上的所有 comment.
var query = new AV.Query("Comments");
query.equalTo("post", 123);
query.find().then(function(results) {
// Create a trivial resolved promise as a base case.
var promise = AV.Promise.as();
_.each(results, function(result) {
// For each item, extend the promise with a function to delete it.
promise = promise.then(function() {
// Return a promise that will be resolved when the delete is finished.
return result.destroy();
});
});
return promise;
}).then(function() {
// Every comment was deleted.
});
each
是underscore.js
里的一个方法,遍历一个collection