2015-09-18 23 views

回答

1

可以使用async模塊,具體這種方法async.eachhttps://github.com/caolan/async#each

https://www.npmjs.com/package/async這裏的故宮包

增加了一個小例子(而不是我的if你想在你的數據庫檢查)

var tests = ['a', 'b']; 
async.each(tests, function(test, callback) { 

    if(test === 'c') { 
    return callback('We cannot have a c') 
    } 

    return callback(); 
}, function(err){ 
    // if any of the file processing produced an error, err would equal that error 
    if(err) { 
     // One of the iterations produced an error. 
     // All processing will now stop. 
     console.log('C was found'); 
    } else { 
     console.log('All Tests are ok'); 
    } 
});