我的_id值来自铁路由器。如何使用流星在mongo collection.findOne()中传递动态_id值?
我的代码:
Template.template_name.helpers({
'edit': function() {
var id = Router.current().params._id;
return Collection.find.One({ _id: id});
}
});
上面的代码不起作用。
我的_id值来自铁路由器。如何使用流星在mongo collection.findOne()中传递动态_id值?
我的代码:
Template.template_name.helpers({
'edit': function() {
var id = Router.current().params._id;
return Collection.find.One({ _id: id});
}
});
上面的代码不起作用。
首先检查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',
});
它是如何不工作?请解释您所面对的行为,并告诉我们您是否有任何错误。看看什么是[mcve]。 –
您在'Collection.find.One({_id:id})'的代码中存在拼写错误。您需要将其重写为'Collection.findOne({_id:id})' – chridam
@Kyll var id正在获取值,但Collection.findOne({_ id:id})没有考虑id值并且给出了未定义的值。如何解决它? –