Skip to content

Instantly share code, notes, and snippets.

@davidnorth
Created August 11, 2011 17:35
Show Gist options
  • Save davidnorth/1140252 to your computer and use it in GitHub Desktop.
Save davidnorth/1140252 to your computer and use it in GitHub Desktop.
Custom helper prevents value in template updating
// In controller:
MyApp.MyController = SC.Object.create({
items: [],
total: function(){
// calculate the total value of items
}.property('items.[]')
})
// A simple custom helper:
Handlebars.registerHelper('formatCurrency', function(property) {
var value = SC.getPath(this, property);
return "£" + Number(value).toFixed(2);
});
// Updates as items are added
{{ MyController.total }}
// Renders correctly initially but won't update as items are added
{{ formatCurrency MyApp.MyController.total }}
// I ended up having to bind to controller property that did formatting, not ideal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment