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'));
 })
});

return: [オブジェクト Promise]

プレーンテキストを取得するにはどうすればよいですか

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

THX!

4

1 に答える 1

10

async、のようにPromiseloadAsyncを返します。ここでそれらをチェーンできます:

$('.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 に答える