0
我的原始文件不會使用本地方法下載,因此我決定使用Node.js,因爲它已經打包在AppJS中,並且zip文件仍然不會在AppJS中執行。與AppJS一起使用NodeJS來打包JSZip
任何幫助,非常感謝。
$(".export").on("click", function() {
var fs = require("fs");
var JSZip = require("jszip");
var zip = new JSZip();
zip.file("hello.txt", "Hello node!");
var content = zip.generate({type:"nodebuffer"});
// saveAs(content, "test.zip");
fs.writeFile("test.zip", content, function(err) {
if (err) throw err;
});
});
body {
background: #fff;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://stuk.github.io/jszip/dist/jszip.min.js"></script>
<script src="http://stuk.github.io/jszip-utils/dist/jszip-utils.js"></script>
<script src="http://stuk.github.io/jszip/vendor/FileSaver.js"></script>
<button class="export">Download</button>
注:我已經嘗試使用File API保存文件,但只希望我已經能夠成功地寫入文件中AppJS是使用Node.js,如下圖所示。
var fs = require("fs");
fs.writeFile("hello.txt", "Hi", function(err) {
if (err) throw err;
});