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