Handlebars助手日期解析没有得到价值
问题描述:
我最近开始玩EmberJS和Handlebars,所以请接受我对这个愚蠢的问题的道歉。我想格式化显示在我的模板中的日期。日期是在ISOString格式和我所试图做的是:Handlebars助手日期解析没有得到价值
我的模板代码:
{{parseDate toDate}} //toDate holds something like 2013-12-02T22:00:00.000Z
我的处理代码:
Handlebars.registerHelper('parseDate', function(value) {
console.log(value); //print string "toDate" not the value of "toDate" - the ISOString
return dateString(value)
});
我相信,这是后话真的很简单,但无法弄清楚。我环顾四周,但没有找到解决方案。
感谢您的帮助!
答
我不知道你的dateString
的功能是什么,但这个辅助工作得很好:http://jsbin.com/odosoy/143/edit
我一直变化不大,只是增加了前面bevor Handlebars
Ember
命名空间,并将其转换为绑定帮手当你的toDate
物业发生变化时,让它重新投降:
Ember.Handlebars.registerBoundHelper('parseDate', function(value) {
console.log(value);
// do any formatting to your value
// I've commented this out since It's not clear from your
// code example what the dateString function does
// return dateString(value);
return value;
});
希望它有帮助。
非常感谢您的快速回答。它帮助了很多。我所缺少的是将助手设置为BoundHelper(愚蠢的我)再次感谢您的快速帮助! – knikolov
不错,易于修复..也为我工作!谢谢 – Roskvist