背景: 我有一个高级数据网格。此ADG的数据提供程序是ArrayCollection。此AC的ID字段上有一个分组集合。
此AC中的两个项目示例AC VAR名称为“arcTemplates”:
(mx.collections::ArrayCollection)#0 filterFunction = (null) length = 69 list = (mx.collections::ArrayList)#1 length = 69 source = (Array)#2 [0] (Object)#3 abbreviation = "sore-throat" insertDate = "11/16/2009" name = "sore throat" templateID = 234 templateType = "New Problem" templateTypeID = 1 [32] (Object)#35 abbreviation = 123 insertDate = "03/08/2010" name = 123 templateID = 297 templateType = "New Problem" templateTypeID = 1 [55] (Object)#58 abbreviation = 1234 insertDate = "11/16/2009" name = 1234 templateID = 227 templateType = "Exam" templateTypeID = 5 [56] (Object)#59 abbreviation = "breast only" insertDate = "03/15/2005" name = "breast exam" templateID = 195 templateType = "Exam" templateTypeID = 5
导致分组的Flex代码示例:
<mx:AdvancedDataGrid displayItemsExpanded="true" id="gridTemplates"> <mx:dataProvider> <mx:GroupingCollection id="gc" source="{arcTemplates}"> <mx:Grouping > <mx:GroupingField name="templateTypeID" compareFunction="gcSort">
GC排序函数:
public function gcSort(a:Object, b:Object):int{ return ObjectUtil.stringCompare(String(a.templateTypeID + a.name).toLowerCase(), String(b.templateTypeID + b.name).toLowerCase()); }
问题: 在我的AC示例中,有一些项,项0、32和56按照它们的TemplateTypeID正确排序和分组,但是项55做了一些奇怪的事情。它似乎按数字5而不是字符串“5”进行排序/分组。变得陌生。如果我将name属性更改为包含文本(所以是1234x),那么它将正确地对字符串“5”进行排序/分组
问题: 这是怎么回事,我该怎么办?
如果我相信你的线索,你就会明白 name=1234 没有引用,所以它被认为是 Number .
name=1234
Number
当你在你的 gcSort String(a.templateTypeID + a.name) ,你这次实际上是在加两个数字( 5+1234 )并将它们转换回 String = & gt; "1239" .
gcSort
String(a.templateTypeID + a.name)
5+1234
String
"1239"
您可以做的是首先将您的名称转换为字符串,然后进行连接:
(a.templateTypeID + a.name.toString()).toLowerCase()