I am using JSZip to generate a zip containing multiple files. The data is coming from the server in JSON format. I am only getting 2 files inside the for loop instead of multiple files. The size of the array of JSON is more than 2 so I expect multiple files not just 2.
var zip = new JSZip();
var root = data.list.dataList;
var length = root.length;
var i;
for(i = 0; i < length; i++){
var aFileName = "a_"+ root[i].type + "_" + root[i].orderNumber + ".xml";//just the name of the file
var aContent = root[i].content; //content of file
var bFileName = "b_"+ root[i].type + "_" + root[i].orderNumber + ".xml";//just the name of the file
var bContent = root[i].content; //content of file
//put files onto a folder
zip.folder("Folder Name").file(aFileName, aContent).file(bFileName, bContent);
}
//generate the zip with all files
var content = zip.generate();
location.href="data:application/zip;base64," + content;
can someone please suggest an alternative since this code only take the content of the last iteration. This is why I can only get 2 files instead of multiple files.