4

我想使用 JSZip 从输入中获取 zip 的内容。我可以阅读文件的标题,但如何获取内容

我尝试使用 jQuery:

$('.upload-input').on('change', function($event) {
 var $file = $event.target.files[0];
 JSZip.loadAsync($file).then(function($content) {
  alert($content.files["css/style.css"].async('text'));
 })
});

返回:[对象承诺]

我该怎么做才能得到纯文本

JSFiddle:https ://jsfiddle.net/jyuy7q6j/

谢谢!

4

1 回答 1

10

async,就像loadAsync返回一个Promise。在这里你可以链接它们:

$('.upload-input').on('change', function($event) {
 var $file = $event.target.files[0];
 JSZip.loadAsync($file).then(function($content) {
  // if you return a promise in a "then", you will chain the two promises
  return $content.files["css/style.css"].async('text');
 }).then(function (txt) {
   alert(txt);
 });
});
于 2016-10-25T16:59:41.790 回答