如何格式化 itemTpl 中的数字?
例子:
'<div style="font-size: 9px;">Total: $ {total}</div>' <= This number {total} must be 100.00, but appears just 100
谢谢!
如何格式化 itemTpl 中的数字?
例子:
'<div style="font-size: 9px;">Total: $ {total}</div>' <= This number {total} must be 100.00, but appears just 100
谢谢!
使用您的成员函数XTemplate
:
itemTpl: new Ext.XTemplate(
'<div style="font-size: 9px;">Total: $ {[this.formatTotal(values.total)]}</div>',
formatTotal: function(total) {
return //formattedTotal
}
)
在此处了解更多信息:http ://docs.sencha.com/touch/2.2.1/#!/api/Ext.XTemplate
正如@kevhender 所说,您可以使用Ext.XTemplate和toFixed javascript 方法进行格式化。
更详细
itemTpl: new Ext.XTemplate(
'<div style="font-size: 9px;">Total: $ {[this.totalFormat(values.total)]}</div>',{
totalFormat : function(total) {
return total.toFixed(2);
}
})