BackGround:,我有一个高级的数据网格。此ADG的数据提供程序是一个ArrayCollection。此AC的ID字段上有一个分组集合。
在这个AC中有几个条目的例子,AC变量名是"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“进行排序/分组。
问题:,这里发生了什么,我如何解决它?
发布于 2010-04-08 21:21:58
如果我信任您的跟踪,您将看到name=1234是不带引号的,因此它被认为是一个Number。
在gcSort String(a.templateTypeID + a.name)中进行操作时,实际上这一次要添加两个数字(5+1234),并将它们转换回String => "1239"。
您可以做的是先将您的名称转换为字符串,然后进行连接:
(a.templateTypeID + a.name.toString()).toLowerCase()https://stackoverflow.com/questions/2602882
复制相似问题