julian
julian

Reputation: 4714

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?

Upvotes: 1

Views: 146

Answers (1)

Dan Dascalescu
Dan Dascalescu

Reputation: 151885

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?

Upvotes: 4

Related Questions