【问题标题】:Meteor server side method callMeteor 服务器端方法调用
【发布时间】:2016-09-05 02:09:09
【问题描述】:
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 的文件夹中的单独 builidingData.js 文件中定义了上述方法。我在 map.onRendered() 下使用以下代码从客户端调用此方法。

Meteor.call('parseFile', (err, res) => {
                if (err) {
                    alert(err);
                } else {
                    // success!
                }
            });

我做了流星meteor add harrison:papa-parse 因此我不必使用脚本标签在 html 代码中包含 papaparse.js。

现在基于以下 cmets,我可以在服务器端打印数据,但出现以下错误:

{ 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 } ],

【问题讨论】:

    标签: javascript meteor papaparse


    【解决方案1】:

    首先,确保 CSV 文件可从您传递到 Papa.parse 的路径 ('/private/file/buildingData.csv') 访问

    其次,尝试将这些作为Papa.parse 呼叫的选项:

    dynamicTyping: true, 
    download: true, //you already have this
    delimiter: ",", //or whatever the delimiter is
    linebreak: "\n", //or whatever your linebreak is
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-17
      相关资源
      最近更新 更多