问题
I am new to meteor js. I got the id from url but i am failing to match it with the id in the mongodb. can any help me
Router.map(function () {
this.route('post', {
template:'viewpost',
path: '/post/:_id',
data: function () {
var id = new ObjectID(this.params._id);
return Tasks.findOne({_id: id});
}
});
回答1:
I suspect you want to return a single task? You access the _id from this.params where this refers to the router.
Router.map(function () {
this.route('post', {
template:'viewpost',
path: '/post/:_id',
data: function () {
return Tasks.findOne(this.params._id);
}
});
In your template you can start referring to the task because it will be the data context for the template;
<p>{{description}}</p>
Assuming you have a description field in your Tasks Collection.
来源:https://stackoverflow.com/questions/28606616/objectid-from-url-to-match-with-one-in-the-mongo-using-meteorjs