javascript - Promise { <pending> } 说,Electron 对话框对象不返回任何内容

标签 javascript html css electron desktop

我正在尝试在我正在构建的教程应用程序上实现 I/O 操作。其他一切都正常工作,我遇到的唯一问题是应用程序没有通过 console.log() 获得所需的结果,这应该是对话框中所选文件的位置。

这是截图

enter image description here

enter image description here

最佳答案

正如 r3wt 所说,当你看到 promise<pending> ,这意味着您没有正确等待异步函数的返回。尝试将 getFileFromUser 函数更改为异步函数,如下所示:

const getFileFromUser = async () => {

    // Triggers the OS' Open File Dialog box. We also pass it as a Javascript
    // object of different configuration arguments to the function

    //This operation is asynchronous and needs to be awaited
    const files = await dialog.showOpenDialog(mainWindow, {
        // The Configuration object sets different properties on the Open File Dialog 
        properties: ['openFile']
    });

    // If we don't have any files, return early from the function
    if (!files) {
        return;
    }

    // Pulls the first file out of the array

    //const file = files[0];
    // Reads from the file and converts the resulting buffer to a string
    //const content = fs.readFileSync(file).toString();

    // Log the Files to the Console
    console.log(files)
}

关于javascript - Promise { <pending> } 说,Electron 对话框对象不返回任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59272351/

相关文章:

html - 列列表中的文本节点不考虑父宽度

css - 字体溢出 Chrome 上的文本输入

javascript - 无法隐藏 Monaco Editor

javascript - 获取产品给定日期

Javascript 计时器不工作(简单但我仍然需要帮助)

javascript - CSS 不适用于(在第一页之后)尝试使用 javascript 打印 html 页面

javascript - 如何在 Javascript 中获取下拉列表的值

javascript - 非常敏感的 onmouseout 行为

html - 我的网页有很多不必要的空格,我该如何解决?

jquery - 连接 CSS 选择器