【问题标题】:how i can do nested levels with iron-router in meteor?我如何在流星中使用 Iron-router 进行嵌套级别?
【发布时间】:2014-05-07 19:45:10
【问题描述】:

我是 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');
    });
  });
});

这是在 emberjs 路由器中完美运行的情况,我如何使用 Iron-router 解决流星中这种类型的嵌套路由级别?

认为可以通过会话解决??

在路由器中

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");
});

【问题讨论】:

    标签: javascript meteor meteorite iron-router


    【解决方案1】:

    您是否尝试混合来自不同框架的代码?我不完全了解您要做什么,但是如果您的路由器正常工作并且您想访问模板中的数据,您应该使用模板数据上下文。

    如果您的路线是这样定义的:

    this.route('your.route', {path: '/yourroute/:_id'});
    

    在你的路由控制器中,你可以试试这个:

    YourTemplateController = RouteController.extend({
        waitOn: function () {
        },
    
        data: function () {
            return this.params._id;
        },
    
        action: function () {
            this.render();
        }
    });
    

    this.params._id现在可以通过这种方式在您的模板事件中访问:

    Template.YourTemplate.events({
    
        "click #v": function(event, template) {
            console.log(template.data);
        }
    
    )};
    

    请注意,事件对象的第二个参数是模板,而不是目标。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-21
      • 2014-11-13
      • 1970-01-01
      • 1970-01-01
      • 2017-07-15
      • 1970-01-01
      相关资源
      最近更新 更多