如何使用meteor在mongo collection.findOne()中传递动态_id值?

时间:2016-02-05 10:06:39

标签: mongodb meteor

我的_id值来自铁路由器。

我的代码:

Template.template_name.helpers({
    'edit': function () {
        var id = Router.current().params._id;
        return Collection.find.One({ _id: id});
    }
});

上述代码不起作用。

1 个答案:

答案 0 :(得分:0)

首先检查ID是否正确返回,不带警报或控制台。

Template.template_name.helpers({
'edit': function () {
    var id = Router.current().params._id;
    alert(id);
    return Collection.find({ _id: id});
  } 
});

在路由器中你必须像这样传递:

Router.route('/template/:_id', {
 name: 'template',
 template: 'template',
});