Flex DatagridColumn LabelFunction 附加参数
我有一个 datagridcolumn,其中定义了 labelFunction:
private function myLabelFunction(item:Object, column:DataGridColumn):String
{
var returnVal:String;
var nm:NumericFormatter;
nm.decimalSeparatorTo = ".";
nm.precision = additionalParameter;
returnVal = nmTwoDecimals.format(item[column.dataField]);
if (returnVal == '0.00')
{
returnVal = '';
}
return returnVal;
}
是否可以添加一个附加参数,以便我可以传递我打算使用的格式化程序的属性值?
例如:
private function myLabelFunction(item:Object, column:DataGridColumn, precisionParam:int):String
{
var returnVal:String;
var nm:NumericFormatter;
nm.decimalSeparatorTo = ".";
nm.precision = precisionParam;
returnVal = nmTwoDecimals.format(item[column.dataField]);
if (returnVal == '0.00')
{
returnVal = '';
}
return returnVal;
}
谢谢。
I have a datagridcolumn where a labelFunction is defined:
private function myLabelFunction(item:Object, column:DataGridColumn):String
{
var returnVal:String;
var nm:NumericFormatter;
nm.decimalSeparatorTo = ".";
nm.precision = additionalParameter;
returnVal = nmTwoDecimals.format(item[column.dataField]);
if (returnVal == '0.00')
{
returnVal = '';
}
return returnVal;
}
Would it be possible to add an additional parameter so that I could pass the property values for the formatter which I intend to use?
Like for example:
private function myLabelFunction(item:Object, column:DataGridColumn, precisionParam:int):String
{
var returnVal:String;
var nm:NumericFormatter;
nm.decimalSeparatorTo = ".";
nm.precision = precisionParam;
returnVal = nmTwoDecimals.format(item[column.dataField]);
if (returnVal == '0.00')
{
returnVal = '';
}
return returnVal;
}
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您必须扩展 DataGridColumn 类。创建新类后,只需覆盖现有的 itemToLabel 函数:
“return labelFunction(data, this);”行是调用 labelFunction 的内容(还将检查所有者数据网格中的 labelfunction)。 “itemToLabel”中的“data”是您的对象。您可以在对象中包含所需的精度值,也可以在扩展类中对其进行硬编码(或注入,或单例,类变量,无论您喜欢什么)。
此时,您可以继续将其作为第三个参数传递给新的 labelFunction。
You would have to extend the DataGridColumn class. After creating your new class simply override the existing itemToLabel function:
The line 'return labelFunction(data, this);' is what calls the labelFunction (will also check the owner datagrid for a labelfunction). 'data' in 'itemToLabel' is your object. You could either include the precision value you want in the object or hard code it in the extended class (or inject, or singleton, class var, whatever you like).
At this point you can go ahead and pass it as a third parameter to your new labelFunction.
在 datagrid 列的标签函数中,您可以使用 dataField 属性访问分配的数据字段,请参阅下面的语法:
“假设您的标签函数称为 formatNumbers_LabelFunction”
这样,您可以使用通用标签函数来处理一些对显示数据进行统一操作
除此之外,您还可以通过调用数据提供程序中的任何数据字段,如下所示:
其中 item 是标签函数方法中的第一个参数 [of type Object]
In your label function for the datagrid column, you can access the assigned data field by using the dataField property, see the following syntax below:
"supposing your label function is called formatNumbers_LabelFunction"
This way, you can use a generic label function to handle some unified operations on your displayed data
And besides that, you can also access to any data field that is in the data provider by just calling its name like this:
where item is the firs parameter [of type Object] in your label function method
这会起作用:
This would work: