我使用Underscore.js的_.invoke()来销毁一个集合,这里是代码:
_.invoke(Labels.selectedItems(), 'destroy', {
error : function (model, response, options) {
self.isFailed = true; // initialized with false
utilities.activateNotification("error", "Deleting label failed", response);
}
});
如何在完成所有销毁功能后添加回调函数(或其他机制?)来检查isFailed的值?
答案 0 :(得分:0)
我认为你最好看看解决这个问题的承诺。
然而,这是一个使用after函数的下划线解决方案:
// function will be called after it has been called as many times as there are items
var allDone = _.after(Labels.selectedItems().length, function(){
console.log('The end');
})
// sample destroy function which calls allDone
var destroy = function(params){
....
allDone();
}