Sencha Touch 2-在项目Tpl上格式化编号



如何格式化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);
      }
})

最新更新