如何解决“当我在代码中迭代数组时,它看起来为空,但是当我在控制台中登录它时,我可以看到项目”?

时间:2018-12-21 11:40:17

标签: javascript node.js coffeescript electron

我正在尝试迭代从promise解析的数组,但是它看起来为空,尽管当我将其登录到控制台时我可以看到项目!

我用咖啡脚本

这是发生问题的功能

folderPath = getUsersHomeFolder()
getFilesInFolder folderPath
.then (files) =>
    inspectAndDescribeFiles folderPath, files
    .then (results) =>
        // hers the problem happen
        displayFile result for result in results 
    .catch (err) =>
        alert 'Sorry, we can not read your files'
        console.log '--- Error in get users files', err

这是inspectAndDescribeFile()函数

inspectAndDescribeFiles = (folderPath, files) ->
new Promise (resolve, reject) =>
    results = []
    for file in files
        resolveFilePath = path.resolve folderPath, file
        inspectAndDescribeFile resolveFilePath
        .then (result) ->
            results.push result
        .catch (err) ->
            results.push err

    resolve results

0 个答案:

没有答案