流星铁路由器session.get不起作用

时间:2014-07-17 07:40:05

标签: meteor iron-router

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

  @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)

什么是正确的方式?

1 个答案:

答案 0 :(得分: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'

尝试一下这些想法,让我知道它是怎么回事。

相关问题