2

背景:我有一个高级数据网格。此 ADG 的数据提供者是一个 ArrayCollection。在这个 AC 的一个 ID 字段上有一个分组集合。

此 AC 中的几个项目的示例,AC var name 是“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”

问题:这里发生了什么,我该如何解决?

4

1 回答 1

2

如果我相信你的踪迹,你会看到它name=1234没有引号,所以它被认为是Number.

当您在 中进行操作时gcSort String(a.templateTypeID + a.name),实际上这次是添加两个数字 ( 5+1234) 并将它们转换回String=> "1239"

您可以做的是首先将您的姓名转换为字符串,然后进行连接:

(a.templateTypeID + a.name.toString()).toLowerCase()
于 2010-04-08T21:21:58.980 回答