电子版: 1.3.3 操作系统: Ubuntu 14.04
我想用Electron将XML对象保存到.xml文件中。我试试这个:
const {dialog} = require("electron").remote;
dialog.showSaveDialog(myObj)
答案 0 :(得分:2)
showSaveDialog()
API不会为您保存文件。您必须使用返回的路径并使用节点保存文件。
const {dialog} = require("electron").remote;
const fs = require('fs');
var savePath = dialog.showSaveDialog({});
fs.writeFile(savePath, fileData, function(err) {
// file saved or err
});
答案 1 :(得分:0)
建议使用从dialog.showSaveDialog返回的路径来获取新版本电子版本的filepath
(在下面的代码中为result.filePath
)
filename = dialog.showSaveDialog({}
).then(result => {
filename = result.filePath;
if (filename === undefined) {
alert('the user clicked the btn but didn\'t created a file');
return;
}
fs.writeFile(filename, content, (err) => {
if (err) {
alert('an error ocurred with file creation ' + err.message);
return
}
alert('WE CREATED YOUR FILE SUCCESFULLY');
})
alert('we End');
}).catch(err => {
alert(err)
})