2013-05-07 3 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 #에는 '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 "#"; 
}); 
관련 문제