2014-07-17 35 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

太棒了!我很高興其中一個工作。 –