Meteor.methods({
'parseFile'() {
Papa.parse('/private/file/buildingData.csv', {
download: true,
complete: function(results) {
console.log("hi there how are you")
console.log(results); // array of rows
return results;
}
});
}
})
我在一个名为Methods的文件夹中的seprate builidingData.js文件中定义了上述方法。我使用以下代码在map.onRendered()下从客户端调用此方法。
Meteor.call('parseFile', (err, res) => {
if (err) {
alert(err);
} else {
// success!
}
});
我做了meteor meteor add harrison:papa-parse
因此我不必使用脚本标记在html代码中包含papaparse.js。
根据以下评论,我现在可以在服务器端打印数据但出现以下错误:
{ data: [ [ '/private/file/buildingData.csv' ] ],
I20160905-12:22:03.973(10)? errors:
I20160905-12:22:03.974(10)? [ { type: 'Delimiter',
I20160905-12:22:03.974(10)? code: 'UndetectableDelimiter',
I20160905-12:22:03.975(10)? message: 'Unable to auto-detect delimiting character; defaulted to
\',\'',
I20160905-12:22:03.976(10)? row: undefined } ],
I20160905-12:22:03.977(10)? meta:
I20160905-12:22:03.978(10)? { delimiter: ',',
I20160905-12:22:03.978(10)? linebreak: '\n',
I20160905-12:22:03.979(10)? aborted: false,
I20160905-12:22:03.979(10)? truncated: false } }
I20160905-12:22:03.986(10)? hi there how are you
I20160905-12:22:03.987(10)? { data: [ [ '/private/file/buildingData.csv' ] ],
I20160905-12:22:03.988(10)? errors:
I20160905-12:22:03.989(10)? [ { type: 'Delimiter',
I20160905-12:22:03.990(10)? code: 'UndetectableDelimiter',
I20160905-12:22:03.990(10)? message: 'Unable to auto-detect delimiting character; defaulted to
\',\'',
I20160905-12:22:03.991(10)? row: undefined } ],
I20160905-12:22:03.992(10)? meta:
I20160905-12:22:03.992(10)? { delimiter: ',',
I20160905-12:22:03.993(10)? linebreak: '\n',
I20160905-12:22:03.999(10)? aborted: false,
I20160905-12:22:03.999(10)? truncated: false } }
I20160905-12:22:04.000(10)? Retrieving current observations...
I20160905-12:22:05.329(10)? finishing
I20160905-12:22:05.330(10)? Retrieving hourly forecast...
I20160905-12:22:06.383(10)? finishing
I20160905-12:22:06.384(10)? Retrieving daily forecast...
I20160905-12:22:07.592(10)? finishing
I20160905-12:22:07.593(10)? hi there how are you
I20160905-12:22:07.593(10)? { data: [ [ '/private/file/buildingData.csv' ] ],
I20160905-12:22:07.594(10)? errors:
I20160905-12:22:07.594(10)? [ { type: 'Delimiter',
I20160905-12:22:07.594(10)? code: 'UndetectableDelimiter',
I20160905-12:22:07.594(10)? message: 'Unable to auto-detect delimiting character; defaulted to
\',\'',
I20160905-12:22:07.595(10)? row: undefined } ],
I20160905-12:22:07.595(10)? meta:
I20160905-12:22:07.596(10)? { delimiter: ',',
I20160905-12:22:07.596(10)? linebreak: '\n',
I20160905-12:22:07.596(10)? aborted: false,
I20160905-12:22:07.597(10)? truncated: false } }
I20160905-12:22:07.598(10)? hi there how are you
I20160905-12:22:07.600(10)? { data: [ [ '/private/file/buildingData.csv' ] ],
I20160905-12:22:07.601(10)? errors:
I20160905-12:22:07.601(10)? [ { type: 'Delimiter',
I20160905-12:22:07.602(10)? code: 'UndetectableDelimiter',
I20160905-12:22:07.602(10)? message: 'Unable to auto-detect delimiting character; defaulted to
\',\'',
I20160905-12:22:07.602(10)? row: undefined } ],
答案 0 :(得分:0)
首先,确保可以从您'/private/file/buildingData.csv'
Papa.parse
)访问CSV文件
其次,请尝试使用这些作为Papa.parse
电话的选项:
dynamicTyping: true,
download: true, //you already have this
delimiter: ",", //or whatever the delimiter is
linebreak: "\n", //or whatever your linebreak is