Meteor Router.go 没有传递参数
Meteor Router.go not passing params
客户端代码片段:
Template.projectEditButton.events({
"click .edit": function() {
Router.go('projectForm', {prjId: this._id});
}
});
至此,this._id正确。在路由器文件中:
Router.route('/projects/form', {
name: 'projectForm',
data: function() {
return Projects.findOne(this.params.prjId);
}
});
this.params 为空。我错过了什么?
您需要将参数添加到路由定义中才能使映射生效:
Router.route('/projects/form/:prjId', {
name: 'projectForm',
data: function() {
return Projects.findOne(this.params.prjId);
}
});
客户端代码片段:
Template.projectEditButton.events({
"click .edit": function() {
Router.go('projectForm', {prjId: this._id});
}
});
至此,this._id正确。在路由器文件中:
Router.route('/projects/form', {
name: 'projectForm',
data: function() {
return Projects.findOne(this.params.prjId);
}
});
this.params 为空。我错过了什么?
您需要将参数添加到路由定义中才能使映射生效:
Router.route('/projects/form/:prjId', {
name: 'projectForm',
data: function() {
return Projects.findOne(this.params.prjId);
}
});