gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 00:36:38 26 4
gpt4 key购买 nike

我正在尝试在我正在构建的教程应用程序上实现 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com