Created
August 25, 2016 21:59
-
-
Save cici004/20b998424eaa0ac6f0582dcab94ff819 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
doDownload : function() { | |
//TEST BEGIN to | |
var urls = []; | |
var rc = this.getRowsAndColumns(); | |
console.dir(rc) | |
for (var i=0, il = rc.rows.length; i<il;i++){ | |
var url = rc.rows[i].requ; | |
if(!urls.includes(url)) | |
urls.push(url); | |
} | |
/* | |
for (var i=0, il = obj.length; i<il;i++){ | |
var obj = resultmap[i].attributes.requ; | |
urls.push(obj); | |
} | |
*/ | |
console.dir(urls) | |
var zip = new JSZip(); | |
console.log("zip = "+zip); | |
var a = document.getElementById("downloadZipLink"); | |
function request(url) { | |
return new Promise(function(resolve) { | |
var httpRequest = new XMLHttpRequest(); | |
httpRequest.open("GET", url); | |
httpRequest.onload = function() { | |
zip.file(url, this.responseText); | |
resolve() | |
} | |
httpRequest.send() | |
}) | |
} | |
Promise.all(urls.map(function(url) { | |
return request(url) | |
})) | |
.then(function() { | |
console.log(zip); | |
zip.generateAsync({ | |
type: "blob" | |
}) | |
.then(function(content) { | |
a.download = "folder" + new Date().getTime(); | |
a.href = URL.createObjectURL(content); | |
a.innerHTML = "download " + a.download; | |
}); | |
}) | |
}, | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment