将数字 5 与字符串“5”分开的分组集合
背景:我有一个高级数据网格。此 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”进行排序/分组。变得陌生了。如果我更改名称属性以包含文本(因此 1234x),它会正确排序/分组为字符串“5”
问题:这里发生了什么以及如何修复它?
BackGround: I have an advanced data grid. The data provider for this ADG is an ArrayCollection. There is a grouping collection on an ID field of this AC.
Example of a couple items within this AC the AC var name is "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
Example of Flex code leading to the Grouping:
<mx:AdvancedDataGrid displayItemsExpanded="true" id="gridTemplates">
<mx:dataProvider>
<mx:GroupingCollection id="gc" source="{arcTemplates}">
<mx:Grouping >
<mx:GroupingField name="templateTypeID" compareFunction="gcSort">
GC sort function:
public function gcSort(a:Object, b:Object):int{
return ObjectUtil.stringCompare(String(a.templateTypeID + a.name).toLowerCase(),
String(b.templateTypeID + b.name).toLowerCase());
}
Problem: In my AC example there are a few items, items 0, 32 and 56 properly sort and group to their templateTypeID, but item 55 does something weird. It seems to sort/group on the numeric 5 instead of the string "5". Gets stranger. If I change the name property to contain text (so 1234x) it then correctly sorts/groups to the string "5"
Question: What is going on here and how do I fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我相信您的跟踪,您会看到
name=1234
是不带引号的,因此它被视为一个Number
。当您在
gcSort
String(a.templateTypeID + a.name)
中执行操作时,实际上您这次添加了两个数字 (5+1234
5+1234) code>) 并将它们转换回String
=>“1239”
。您可以做的就是首先将您的名字转换为字符串,然后进行串联:
If i trust your trace, you see that
name=1234
is written without quote, so it is considered as aNumber
.When you are doing in your
gcSort
String(a.templateTypeID + a.name)
, you are in fact this time adding two numbers (5+1234
) and convert them back to aString
=>"1239"
.What you can do is convert first your name into string and then do your concatenation: