2013-05-07 24 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 "#"; 
});