I have a date/time formatting helper but what it produces does not update when the underlying property changes. This is not a surprise, but does anyone know how to produce bindings in helpers?
I invoke the helper like this...
{{timestamp created_at}}
...and here is the helper itself:
Handlebars.registerHelper('timestamp', function(context, options) {
var formatter = options.hash['format'] ? options.hash['format'] : 'hh:mm a MM-DD-YYYY';
var original_date = Ember.getPath(this, context); // same as this.get(context) ?
var parsed_date = moment(original_date);
var formatted_date = parsed_date.format(formatter);
return new Handlebars.SafeString("<time datetime=" + original_date +">" + formatted_date + "</time>");
});
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…