使用Papa Parse导入流星中utf-8编码的csv [英] Importing utf-8 encoded csv in meteor using Papa Parse
问题描述
我无法从一个流星应用程序(流星应用程序1)以CSV格式导出某些数据,然后将该CSV文件上传到单独的流星应用程序(流星应用程序2).具体来说,虽然文件是使用utf-8编码从流星应用程序1导出的,但我不知道如何告诉" csv编码为utf-8格式的流星应用程序2.结果,流星应用程序2接收到的数据被utf-8术语(如%u2019"等)破坏了
I am having trouble exporting some data from one meteor application (meteor application 1) as a CSV, then uploading that CSV file to a separate meteor application (meteor application 2) . Specifically, while the file is exported from meteor application 1 with utf-8 encoding, I do not know how to "tell" meteor application 2 that the csv encoded in utf-8 format. As a result, the data, as received by meteor application 2 gets corrupted with utf-8 jargon like "%u2019" etc
我使用的是来自amos.js的Clinical:csv软件包,该软件包是基于Papa Parse构建的.
I’m using the package clinical:csv from atmosphere.js, which is built on top of Papa Parse.
流星应用程序1中相关的代码输出行是:
The relevant exporting lines of code in meteor application 1 are:
'click #exportMe':function(){
var csvContent = CSV.unparse(Tasks.find().fetch());
window.open('data:text/csv;charset=utf-8,' + escape(csvContent), '_self');
},
流星应用程序2中相关的代码导入行为:
The relevant importing lines of code in meteor application 2 are:
Template.example.events({
'change #hiddenUpload': function(event){
var filesList = event.currentTarget.files;
var file = filesList[0];
Papa.parse(file, {
header:true,
complete: function(results) {
var data = results.data
Meteor.call('tasks.batch',data)
}
});
},
})
我想可能会有一种在导入代码中进行指定的方法,该代码是用utf-8编码的,但是在任何相关文档中都找不到.
I would guess that there would be a way of specifying in the importing code, that it’s encoded in utf-8, but have not been able to find anything in any relevant documentation.
非常感谢您的帮助.
推荐答案
在您的代码中,尝试放置如下所示的编码选项:
In your code, try putting a encoding option like below:
Papa.parse(file, {
header:true,
encoding: "ISO-8859-1",
complete: function(results) {
var data = results.data
Meteor.call('tasks.batch',data)
}
});
这篇关于使用Papa Parse导入流星中utf-8编码的csv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!