this._id 在 Meteor 中未定义
this._id undefined in Meteor
我试图在路由到页面时设置我的 selectedDocId
,但 Meteor 抛出 undefined
。我正在使用 onBeforeAction
试图存储通过 /:id
在我的 url 末尾连接的 id
,但我无法使它们对齐。
Router.route('speaker', {
path:'/speakers/:_id',
template: 'speaker',
data: function(){
return Speakers.findOne(this.params._id);
},
onBeforeAction: function(){
console.log('speaker route has run');
Session.set('selectedDocId', this._id);
//returns undefined
console.log(this._id);
this.next();
}
});
Template.speaker.helpers({
editingDoc: function(){
return Speakers.findOne({_id: Session.get('selectedDocId')});
}
});
而不是 this._id
,使用 this.params._id
,就像您在 data
挂钩中所做的那样。
我试图在路由到页面时设置我的 selectedDocId
,但 Meteor 抛出 undefined
。我正在使用 onBeforeAction
试图存储通过 /:id
在我的 url 末尾连接的 id
,但我无法使它们对齐。
Router.route('speaker', {
path:'/speakers/:_id',
template: 'speaker',
data: function(){
return Speakers.findOne(this.params._id);
},
onBeforeAction: function(){
console.log('speaker route has run');
Session.set('selectedDocId', this._id);
//returns undefined
console.log(this._id);
this.next();
}
});
Template.speaker.helpers({
editingDoc: function(){
return Speakers.findOne({_id: Session.get('selectedDocId')});
}
});
而不是 this._id
,使用 this.params._id
,就像您在 data
挂钩中所做的那样。