2014-07-17 34 views
0

我想实现这个路线:流星铁路由器session.get不起作用

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

但显然我不能使用session对象这种方式。

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

什么是正确的方法?

回答

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' 

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

+0

我确认,目前,您无法将函数关联到yieldtemplate。但是你的解决方法可以完成这项工作。谢谢! – ndemoreau

+0

太棒了!我很高兴其中一个工作。 –