简体   繁体   中英

Meteor method doesn't work

Assume that I have a Collection called Tasks which has few tasks in it.
I call a method to return a task array to the user but for some reason it doesn't return anything.

Here is a code for example:

if (Meteor.isClient) {
// This code only runs on the client
    Template.body.helpers({
       tasks: function () {
            // Show newest tasks first
            Meteor.call("getTasks", function(error, result) {
                return result; // Doesn't do anything..
            });
        }
    });
}

Meteor.methods({
    getTasks: function() {
        return Tasks.find({}, {sort: {createdAt: -1}});
    }
});

Any ideas why when I call the method it doesn't return anything?

Tasks.find() returns a cursor, which makes no sense to transmit to the client via DDP .

You probably mean to return Tasks.find().fetch() , but that defeats the purpose of Meteor's very nice data synchronization mechanism.

Have you read Understanding Meteor's publish/subscribe ?

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