我有一個文件路徑列表file_paths
,我想檢測哪個文件存在。 如果有任何文件存在,我想閱讀那個文件。否則,請調用另一個函數,例如 not_found
。Node.js'未找到'async.detect回調?
我希望使用async.detect
,但是當所有迭代器返回false
時,我找不到添加'未找到'回調 的方法。
我試過這個,但沒有工作。返回未定義,並沒有輸出。
async = require 'async'
async.detect [1,2,3], (item, callback) ->
callback true if item == 4
, (result) ->
console.log result ? result : 'Not Found'
如果還有其他方法可以做,請將其添加到答案中。
請包括您嘗試過的代碼塊。 – mithunsatheesh