简体   繁体   中英

Meteor server side method call

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;
            }
        });
    }
})

I have defined above methos in a seprate builidingData.js file in a folder named Methods. And I am calling this method from client under map.onRendered() using following code.

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

I did meteor meteor add harrison:papa-parse hence i don't have to use script tag to include papaparse.js in html code.

Based on below comments now I am able to print data on server side but with following error:

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

First, make sure the CSV file is accessible from that path ( '/private/file/buildingData.csv' ) you're passing into Papa.parse

Second, try these as your options to the Papa.parse call:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM