Electron dialog.showOpenDialog 不是 运行 回调
Electron dialog.showOpenDialog not running callback
我一直在尝试制作一个简单的程序来使用 Electron 创建和读取文件。
到目前为止,我已经尝试了很多,似乎我提供的 dialog.showOpenDialog 回调函数没有被调用。
dialog.showOpenDialog( (filePaths) => {
console.log('this callback is called');
console.log(filePaths);
});
//Directly read a test file
fs.readFile('readtest.txt', 'utf-8', (err, data) => {
if (err) throw err;
console.log(data);
});
这是我的阅读按钮处理程序中的代码。
对话框打开,我选择了一个文件,但它什么也没做。
然而,我选择的同一个文件被 fs.readFile 读取并显示在控制台中。
我选择文件后似乎没有调用回调。
它 returns 一个承诺,所以你可以用 .then 链接它:
dialog.showOpenDialog(null, options).then((filePaths) => {
console.log('this callback is called');
console.log(filePaths);
});
我一直在尝试制作一个简单的程序来使用 Electron 创建和读取文件。 到目前为止,我已经尝试了很多,似乎我提供的 dialog.showOpenDialog 回调函数没有被调用。
dialog.showOpenDialog( (filePaths) => {
console.log('this callback is called');
console.log(filePaths);
});
//Directly read a test file
fs.readFile('readtest.txt', 'utf-8', (err, data) => {
if (err) throw err;
console.log(data);
});
这是我的阅读按钮处理程序中的代码。 对话框打开,我选择了一个文件,但它什么也没做。 然而,我选择的同一个文件被 fs.readFile 读取并显示在控制台中。
我选择文件后似乎没有调用回调。
它 returns 一个承诺,所以你可以用 .then 链接它:
dialog.showOpenDialog(null, options).then((filePaths) => {
console.log('this callback is called');
console.log(filePaths);
});