grid里面的一个列的格式渲染,用到了一个自定义的函数:
{
header : "Spending",
dataIndex : 'spending',
align : 'right',
renderer : CurrencyFormat()
}
函数的定义如下
var NumberReg = /(\d+)(\d{3})/;
var DEFAULT_CURRENCY = '$';
NumberFormat = function(v) { //这个函数是渲染一般的数值数据,如12345,显示为12,345
var whole = String(v);
while (NumberReg.test(whole)) {
whole = whole.replace(NumberReg, '$1' + ',' + '$2');
}
return whole;
}
CurrencyFormat = function(currency) { //这个函数是渲染金额数据,如12345,显示为$12,345
return function(v) { //[color=#FF0000]开始看不懂了,这个用法...currency、v如是参数到底是怎么传递的?(问题一)[/color]
var txt = NumberFormat(v);
if (!currency) {
currency = DEFAULT_CURRENCY;
}
if (v < 0) {
return "-" + currency + txt.substring(1);
} else {
return currency + txt;
}
}
}
第二个问题是:Extjs有没有自己定义好的渲染各种数据显示的方法,最常用的方法是怎么用的?