Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将回调函数添加到下划线_Javascript_Underscore.js - Fatal编程技术网

Javascript 将回调函数添加到下划线

Javascript 将回调函数添加到下划线,javascript,underscore.js,Javascript,Underscore.js,我正在使用underline.js的u.invoke()销毁一个集合,下面是代码: _.invoke(Labels.selectedItems(), 'destroy', { error : function (model, response, options) { self.isFailed = true; // initialized with false utilities.activateNotification("error", "Deleting labe

我正在使用underline.js的u.invoke()销毁一个集合,下面是代码:

 _.invoke(Labels.selectedItems(), 'destroy', {
   error : function (model, response, options) {
     self.isFailed = true; // initialized with false
     utilities.activateNotification("error", "Deleting label failed", response);
   }
 });

在所有销毁函数完成后,如何添加回调函数(或其他机制?)来检查isFailed的值?

我认为您最好看看解决此问题的承诺

但是,这里有一个下划线解决方案,它利用了函数:

// 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();
}