var nation_export_save = function(req, res) { var encode = req.body.encode;(encode为‘utf8’ or 'GBK’) var sname = req.body.sname; var items = req.body.items; Nation.find({}, function(err, nations) { if (sname == ‘JSON’) { res.attachment(‘nation.txt’); res.send(nations); } else if (sname == ‘CSV’) { var ites = []; var lines = items.split(‘,’); for (var i = 0; i < lines.length; i++) { ites.push(lines[i]); }; json2csv({ data: nations, fields: ites }, function(err, csv) { var iconv = new Iconv('UTF-8’, encode); content = iconv.convert(csv); res.attachment(‘nation.csv’); res.send(content); })
};
})
}