javascript - Electron dial.showOpenDialog() 过滤器不起作用

标签 javascript node.js electron

我正在 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/

相关文章:

python - 使用 Electron 应用程序时如何从 Angular 组件与 Python 后端通信?

javascript - 如何让我的滑动条通过刷新保持位置

javascript - 在 JavaScript 中使用数组?

javascript - 如何基于另一个对象数组创建一个对象数组?

node.js - 从嵌套回调而不是父函数返回值

javascript - 从 Electron 中所需的 JS 模块访问父变量

javascript - 从 jquery 到页面变量

javascript - 如何确保我不会将内容替换为旧响应?

node.js - 创建一个监听 `net` 流的服务器并使用 Node.js 进行回复

node.js - node-windows权限被拒绝-编译后不请求权限?