本文介紹了電子對話框不保存文件的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
電子版:1.3.3操作系統:Ubuntu 14.04
我想使用 Electron 將 XML 對象保存到 .xml 文件中.我試試這個:
I want to save a XML object into a .xml file with Electron. I try this:
const {dialog} = require("electron").remote;
dialog.showSaveDialog(myObj)
一個新窗口正在打開,我填寫了文件名但沒有保存任何內容.
A new windows is opening, I fill the name of the file but nothing has been saving.
推薦答案
showSaveDialog()
API 不會為您保存文件.您必須使用返回的路徑并使用 Node 來保存您的文件.
The showSaveDialog()
API does not save the file for you. You must use the returned path and use Node to save your file.
const {dialog} = require('electron').remote;
const fs = require('fs');
dialog.showSaveDialog({}).then((result) => {
fs.writeFile(result.filePath, MyFileData, (err) => {
// file saved or err
});
}).catch((err) => {
// err
});
這篇關于電子對話框不保存文件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!