我正在 GitHub 上开发一个 IDE 的分支,主要问题之一是它将文件保存到 cookie,而不是普通计算机。因此,我需要一种保存和打开文件的方法。我已经使用 blob 关闭了保存文件系统。然而,根据控制台,打开的文件提供了一个“意外的字符串”,尽管它非常普通。
下面是函数:
function openFileCMD() {
console.log('Opening File...');
dialog.showOpenDialog( (fileName), {
filters: [{
name: 'Text Files',
extensions: ['txt']
}, {
name: 'HTML Files',
extensions: ['html', 'htm']
}, {
name: 'Rich Text File',
extensions: ['rtf']
}, {
name: 'XML/YAMLFile',
extensions: ['xml', 'yml', 'yaml']
}, {
name: 'JSON File',
extensions: ['json'] }
]} => {
if(fileName === undefined) {
console.log("Ouch. That wall hurt. Can you pick a file this time? Please?");
// document.getElementsByClassName('alert')[0].style.display = "block";
return;
}
fs.readFile(fileName[0], 'utf-8', (err, data) => {
if(err){
alert("Woah. Something went wrong. Check the console for more info.");
console.log("An error occured reading the file : " + err.message);
return;
} else {
document.getElementById("code-editor").value = "<pre><code>" + data + "</code></pre>";
}
});
closeSidebar();
}
提前感谢任何可以帮助解决此问题或为我指明解决此问题的正确方向的人! :)
编辑:我已尝试在一行中使用 dialog.showOpenDialog
:仍然无济于事。
最佳答案
您收到的“意外字符串”错误消息与过滤器无关,而是与 dialog.showOpenDialog 有关。没有正确调用...
dialog.showOpenDialog (filename, options => { ... });
应该改为:
dialog.showOpenDialog (options, filename => { ... });
关于javascript - Electron dial.showOpenDialog() 过滤器不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52235804/