【问题标题】:meteor iron-router session.get doesn't work流星铁路由器 session.get 不起作用
【发布时间】:2014-09-07 23:21:47
【问题描述】:

我正在尝试实现这条路线:

  @route "buildingSpaceTenant",
    path: "/buildings/:_building_id/spaces/:_space_id/tenants/:_id/communications"
    template: "tenant"
    yieldTemplates: {
      Session.get("current_tenant_subtemplate"): {to: "subTemplate"}
    }

但显然我不能以这种方式使用会话对象。

<runJavaScript-30>:148:11: client/routes/tenantsRoute.coffee:44: unexpected . (compiling client/routes/tenantsRoute.coffee) (at handler)

什么是正确的方法?

【问题讨论】:

    标签: meteor iron-router


    【解决方案1】:

    您不能将变量名用作对象字面量中的键。如果yieldTemplates 可以接受一个函数(我不认为它可以),你可以尝试类似:

    @route 'buildingSpaceTenant',
      path: '/buildings/:_building_id/spaces/:_space_id/tenants/:_id/communications'
      template: 'tenant'
      yieldTemplates: ->
        templateName = Session.get 'current_tenant_subtemplate'
        obj = {}
        obj[templateName] = to: 'subTemplate'
        obj
    

    我查看了来自 this issue 的示例,这意味着您可以尝试覆盖 action 以实现相同的最终结果。

    @route 'buildingSpaceTenant',
      path: '/buildings/:_building_id/spaces/:_space_id/tenants/:_id/communications'
      template: 'tenant'
      action: ->
        if @ready()
          @render()
          templateName = Session.get 'current_tenant_subtemplate'
          @render templateName, to: 'subTemplate'
        else
          @render 'loading'
    

    试试这些想法,然后告诉我进展如何。

    【讨论】:

    • 我确认,目前,您无法将函数关联到 yieldtemplate。但是您的解决方法可以完成工作。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2016-01-22
    • 1970-01-01
    • 2014-09-03
    • 1970-01-01
    • 2016-05-04
    • 2015-08-11
    • 1970-01-01
    • 2014-04-22
    相关资源
    最近更新 更多