2013-05-07 51 views
1

我試圖建立一個幫助解決ULR路線,像這樣:如何評價在車把助手變量

Handlebars.registerHelper('rails_route', function(route, options) { 
    var fn = Routes[route]; 
    if(typeof fn === 'function') { 
    var opts = {}; 
    for (var key in options.hash) { 
     var value = options.hash[key]; 
     opts[key] = options.fn(value); // Uncaught TypeError: Object #<Object> has no method 'fn' 
     } 
     return fn(opts); 
    } 
    return "#"; 
}); 

而且我把這種幫助是這樣的:

<ul class="dropdown-menu"> 
    {{#each membership in controllers.currentUser.user.memberships}} 
    <li> 
    <a href="{{rails_route root_path firm_id=membership.firm.id }}">{{membership.firm.name}}</a> 
    </li> 
{{/each}} 
</ul> 

我需要評估「membership.firm.id」但我很快得到「Uncaught TypeError:Object#has no method'fn'」。什麼是正確的方法來做到這一點?

回答

0

我讓它工作,謝謝! ;)

我的模板

<ul class="dropdown-menu"> 
    {{#each membership in controllers.currentUser.user.memberships}} 
    {{#with membership.firm}} 
     <li> 
     <a href="{{rails_route root_path firm_id=id }}">{{name}}</a> 
     </li> 
    {{/with}} 
{{/each}} 
</ul> 

幫助我

Handlebars.registerHelper('rails_route', function(route, options) { 
    var fn = Routes[route]; 
    if(typeof fn === 'function') { 
    var opts = {}; 
    for (var key in options.hash) { 
     var value = options.hash[key]; 
     opts[key] = this.get(value); 
     } 
     return fn(opts); 
    } 
    return "#"; 
});