Wil*_*227 0 html javascript css desktop electron
我正在尝试在我正在构建的本教程应用程序上实现 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)
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
723 次 |
| 最近记录: |