Meteor 流星:如何计算收集的数据?

Meteor 流星:如何计算收集的数据?,meteor,Meteor,我在计算集合中的一些数据时遇到问题。这个代码对我不起作用。有人能帮我吗 客户端代码: Template.count_status.helpers({ countcategory: function(){ return Profil.find({ status: 'Available', category: { $in: ['PTR', 'KOM'] }, }).count(); } }); 服务器代

我在计算集合中的一些数据时遇到问题。这个代码对我不起作用。有人能帮我吗

客户端代码:

Template.count_status.helpers({
    countcategory: function(){
        return Profil.find({
            status: 'Available',
            category: { $in: ['PTR', 'KOM'] },
        }).count();
    }
});
服务器代码:

Meteor.methods({
    countcategory: function () {
        return Profil.find().count();
    }
});

确保您已订阅“profil”集合(客户端)。并在服务器代码中发布。我假定您没有使用pub/sub函数

确保已将autopublish软件包添加到您的软件包中(对于要使用的客户端代码)

您没有使用上面粘贴的服务器代码

您可以使用以下代码调用服务器方法:

Template.count_status.helpers({
    countcategory: function(){
        Meteor.call('countcategory', function(err,res){
            if(err){
                //do something with err
            }
            else{
                //do something with result
            }
        });
    }
});

您是否在客户端中调用了服务器方法?