Javascript 如何在meteor中使用铁路由器进行嵌套级别?
我是铁路由器的新手,这里有个问题(代码如下) 使用陨石和流星0.8.1Javascript 如何在meteor中使用铁路由器进行嵌套级别?,javascript,meteor,meteorite,iron-router,Javascript,Meteor,Meteorite,Iron Router,我是铁路由器的新手,这里有个问题(代码如下) 使用陨石和流星0.8.1 App.Router.map(function() { this.resource('post', { path: '/post/:post_id' }, function() { this.route('edit'); this.resource('comments', function() { this.route('new'); }); }); }); 这就是在emberj
App.Router.map(function() {
this.resource('post', { path: '/post/:post_id' }, function() {
this.route('edit');
this.resource('comments', function() {
this.route('new');
});
});
});
这就是在emberjs路由器中完美工作的情况,我如何在meteor with iron路由器中解决这种嵌套级别的路由问题
认为它可以通过会话解决
路由器内
this.route("v", {onBeforeAction: function() {Session.set('uniqueId', this.params._id);}, path: "/v/:_id"});
在Template.v.events中
"click #v": function(event, target) {
event.preventDefault();
Accounts.verifyEmail(Session.get('uniqueId'), function(error) {
if(error) throwError(error.reason); else Meteor.Router.to("/profile");
});
您是否试图混合来自不同框架的代码?我并不完全清楚您正在尝试做什么,但是如果您的路由器工作正常,并且您希望访问模板中的数据,那么您应该使用模板数据上下文 如果您的路线是这样定义的:
this.route('your.route', {path: '/yourroute/:_id'});
Template.YourTemplate.events({
"click #v": function(event, template) {
console.log(template.data);
}
)};
在路线的控制器中,您可以尝试以下操作:
YourTemplateController = RouteController.extend({
waitOn: function () {
},
data: function () {
return this.params._id;
},
action: function () {
this.render();
}
});
现在可以通过以下方式在模板事件中访问this.params.\u id
:
this.route('your.route', {path: '/yourroute/:_id'});
Template.YourTemplate.events({
"click #v": function(event, template) {
console.log(template.data);
}
)};
请注意,events对象的第二个参数是模板,而不是目标