1

I'm trying to build a helper to resolve ulr routes, like this:

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 "#";
});

And i call this helper like this:

<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>

I need to evaluate "membership.firm.id" but i alaways get "Uncaught TypeError: Object # has no method 'fn' ". What is the right way to do this?

4

1 回答 1

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 "#";
});
于 2013-05-07T09:37:35.110 回答