Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 20th, 2012  |  syntax: JavaScript  |  size: 0.67 KB  |  hits: 27  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Ember.Handlebars.registerHelper('short_price', function(property) {
  2.    
  3.     console.log(this.getPath(property));   // <--- prints undefined
  4.  
  5.     var value = this.getPath(property), short_price = parseFloat(value).toFixed(2);
  6.    
  7.     // left pad with spaces so that numbers are aligned
  8.     // var short_price = _.str.lpad(String(short_price), 7, " ")
  9.     // ^ doesn't align. need fixed-width fonts but looks awful
  10.    
  11.     return new Handlebars.SafeString(short_price);
  12. });
  13.  
  14.  
  15. // Template
  16.  
  17. {{#each item in controller}}
  18.    {{#view App.Item itemBinding="item"}}
  19.         <span>{{item.number}}</span>
  20.         <span class="numeric">{{short_price item.total}}</span>
  21.    {{/view}}
  22. {{/each}}