我有一个对象。单击按钮时,对象存储在变量中。在同样的点击功能,我需要将该对象导出到Meteor中的xls(excel)文件。有帮助吗?
html page
<button class="export-data btn btn-success" type="submit" >Export Data</button>
JavaScript file, client side
Template.ExportActivationCodes.events({
"click .export-data": function (event, template) {
var advertiserdatas = template.find("#exportId").value;
var nameFile = 'fileDownloaded.csv';
Meteor.call('download',advertiserdatas, function(err, fileContent) {
if (fileContent) {
var blob = new Blob([fileContent], {type: "text/plain;charset=utf-8"});
saveAs(blob, nameFile);
}
});
}
});
Meteor methods server side
download: function(advertiserdatas) {
var collection = ActivationCodes.find({advertiserId:parseInt(advertiserdatas)}).fetch();
var heading = true; // Optional, defaults to true
var delimiter = ";" // Optional, defaults to ",";
return exportcsv.exportToCSV(collection, heading, delimiter);
}