spark.collectionsSort 提供在现有视图上建立排序所需的排序信息(ICollectionView 接口或实现此接口的类)。The <s:Sort> tag has the following attributes:

  <s:Sort
  Properties
  compareFunction="Internal compare function"
  fields="null"
  unique="false | true"
  />
  

In case items have inconsistent data types or items have complex data types, use of default built-in compare functions is not desired. Inconsistent sort result may occur in such cases. To avoid such problem, provide custom compare function and/or make item types consistent.

]]>
mx.collections:ISortmx.styles:AdvancedStyleClient 提供在现有视图上建立排序所需的排序信息(ICollectionView 接口或实现此接口的类)。将 Sort 实例分配给视图的 sort 属性后,必须调用该视图的 refresh() 方法才能应用此排序条件。

通常,这种排序是针对包含复杂项目的集合定义的,这样的集合是指那些对其中的对象的一个或多个属性执行排序的集合。以下示例显示了这种用法:


     var col:ICollectionView = new ArrayCollection();
     // In the real world, the collection would have more than one item.
     col.addItem({first:"Anders", last:"Dickerson"});
 
     // Create the Sort instance.
     var sort:ISort = new Sort();
 
     // Set the sort field; sort on the last name first, first name second.
     var sortfieldLastName:ISortField = new SortField("last",true);
     var sortfieldFirstName:ISortField = new SortField("first",true);
 
     // Set the locale style to "en-US" to cause the strings
     // to be ordered according to the rules for English as used in the USA.
     sortfieldLastName.setStyle("locale","en-US");
     sortfieldFirstName.setStyle("locale","en-US");
     sort.fields = [sortfieldLastName, sortfieldFirstName];
 
     // Assign the Sort object to the view.
     col.sort = sort;
 
     // Apply the sort to the collection.
     col.refresh();
  

也有集合中包含简单项目(如 StringDateBoolean 等)的情形。在这种情况下,可直接对简单类型应用排序。在构造简单项目的排序时,请使用一个排序字段,并在 SortField 对象构造函数中指定 null name(第一个)参数。例如:


     import mx.collections.ArrayCollection;
     import spark.collections.Sort;
     import spark.collections.SortField;
 
     var col:ICollectionView = new ArrayCollection();
     col.addItem("California");
     col.addItem("Arizona");
     var sort:Sort = new Sort();
 
     // There is only one sort field, so use a null 
     // first parameter. 
     var sortfield:SortField = new SortField("null",true);
 
     // Set the locale style to "en-US" to set the language for the sort.
     sortfield.setStyle("locale","en-US");
     sort.fields = [sortfield];
     col.sort = sort;
     col.refresh();
  

ICollectionView 接口的 Flex 实现将先检索远程位置的所有项目,然后再执行排序。如果要对排序后的列表使用分页,请在检索数据之前对远程集合应用排序。

SortField 类提供的默认比较可以将字符串按照特定语言进行正确排序。可以按照以下方式之一,设置类的实例的区域设置样式以选择语言:

  • 在 MXML 声明中使用该类,并从包含声明的文档中继承区域设置。
  • 示例:
      <fx:Declarations> 
             <s:SortField id="sf" /> 
      </fx:Declarations>
      
  • 使用 MXML 声明并在赋值列表中指定区域设置值。
  • 示例:
      <fx:Declarations> 
          <s:SortField id="sf_SimplifiedChinese" locale="zh-Hans-CN" /> 
      </fx:Declarations>
      
  • 调用 setStyle 方法,如 sf.setStyle("locale", "zh-Hans-CN")
  • 调用 UIComponent 的 addStyleClient() 方法来继承 UIComponent 的样式。
mx.collections.ICollectionViewspark.collections.SortFieldSort 构造函数。 构造函数。

创建一个不带字段集和自定义比较运算符的新 Sort。

findItem itemsvaluesmodereturnInsertionIndexfalsecompareFunctionnull propertyAffectsSort property reverse sort items ANY_INDEX_MODE 执行查找时返回任何匹配项的索引。any 执行查找时返回任何匹配项的索引。 FIRST_INDEX_MODE 执行查找时返回第一个匹配项的索引。first 执行查找时返回第一个匹配项的索引。 LAST_INDEX_MODE 执行查找时返回最后一个匹配项的索引。last 执行查找时返回最后一个匹配项的索引。 compareFunction fields null SortFieldunique false
NumericDataProvider 此 IList 类生成的各项是一个连续的数字序列。mx.collections:IListmx.utils:OnDemandEventDispatcher 此 IList 类生成的各项是一个连续的数字序列。minimummaximum 属性之间的数字范围。stepSize 属性定义相邻项之间的差。

 <s:SpinnerList>
   <s:dataProvider>
     <s:NumericDataProvider minimum="0" maximum="23" stepSize="1"/>
   </s:dataProvider>
 </s:SpinnerList> 
 

此类的优点是项值在需要时才计算,而不是存储项值。

spark.components.SpinnerListmx.collections.IListNumericDataProvider 构造函数。 构造函数。 addItemAt 不支持此函数.itemindex 不支持此函数. addItem 不支持此函数.item 不支持此函数. getItemAt indexprefetch0 getItemIndex item itemUpdated 不支持此函数.itempropertynulloldValuenullnewValuenull 不支持此函数. removeAll 不支持此函数. 不支持此函数. removeItemAt 不支持此函数.index 不支持此函数. setItemAt 不支持此函数.itemindex 不支持此函数. toArray length maximum 最后一项的值。100 最后一项的值。此值必须大于最小值。 minimum 第一项的值。0 第一项的值。此值必须小于最小值。 stepSize stepSize 属性控制第一项和最后一项之间的各项的值。1 stepSize 属性控制第一项和最后一项之间的各项的值。对于每个项,值计算为 minimum 和该项的索引与此属性的乘积之和。

例如,如果 minimum 是 10,maximum 是 20,此属性是 3,则此数据提供程序的项值为 10、13、16、19 和 20。

SortField 提供对集合视图中的字段或属性建立排序所需的排序信息。The <s:SortField> tag has the following attributes:

  <s:SortField
  Properties
  compareFunction="Internal compare function"
  descending="false"
  name="null"
  numeric="null"
  />
  
]]>
mx.collections:ISortFieldmx.styles:AdvancedStyleClient 提供对集合视图中的字段或属性建立排序所需的排序信息。SortField 类打算与 Sort 类一起使用。通常,这种排序是针对包含复杂项目的集合定义的,复杂项目是指那些要在其中对这些对象的属性执行排序的项目。如下例所示:

     var col:ICollectionView = new ArrayCollection();
     col.addItem({first:"Anders", last:"Dickerson"});
     var sort:Sort = new Sort();
     var sortfield:SortField = new SortField("first", true);
     sortfield.setStyle("locale", "en-US");
     sort.fields = [sortfield];
     col.sort = sort;
  
也有集合中包含简单项目(如 StringDateBoolean 等)的情形。在这种情况下,应直接对简单类型应用排序。在这种情况下构造排序时,只需要一个排序字段,且不应指定 name。例如:

     var col:ICollectionView = new ArrayCollection();
     col.addItem("California");
     col.addItem("Arizona");
     var sort:Sort = new Sort();
     var sortfield:SortField = new SortField(null, true);
     sortfield.setStyle("locale", "en-US");
     sort.fields = [sortfield];
     col.sort = sort;
  

SortField 类提供的默认比较可以将字符串按照特定语言进行正确排序。可以按照以下方式之一,设置类的实例的区域设置样式以选择语言:

  • 在 MXML 声明中使用该类,并从包含声明的文档中继承区域设置。
  • 示例:
      <fx:Declarations> 
             <s:SortField id="sf" /> 
      </fx:Declarations>
      
  • 使用 MXML 声明并在赋值列表中指定区域设置值。
  • 示例:
      <fx:Declarations> 
          <s:SortField id="sf_SimplifiedChinese" locale="zh-Hans-CN" /> 
      </fx:Declarations>
      
  • 调用 setStyle 方法,如 sf.setStyle("locale", "zh-Hans-CN")
  • 调用 UIComponent 的 addStyleClient() 方法来继承 UIComponent 的样式。
mx.collections.ICollectionViewspark.collections.SortSortField 构造函数。namenull此字段用来进行比较的属性的名称。如果该对象为简单类型,则传递 nulldescendingfalse指示比较运算符是否按降序排列项目。 numericnull指示比较运算符是否按编号而不按字母顺序比较排序项目。 构造函数。 initializeDefaultCompareFunction obj reverse arraySortOnOptions compareFunction 用于在对关联集合的项目进行排序时比较两个项目的函数。 用于在对关联集合的项目进行排序时比较两个项目的函数。如果指定了 ISort 对象中的 compareFunction 属性,则 Flex 会忽略 ISort 的 SortField 对象的所有 compareFunction 属性。

该比较函数必须具有以下签名:

function myCompare(a:Object, b:Object):int

此函数必须返回以下值:

  • -1,如果在已排序序列中 Object a 应显示在 Object b 之前。
  • 0,如果 Object a 等于 Object b
  • 1,如果在已排序序列中 Object a 应显示在 Object b 之后。

默认值为可以按升序或降序执行字符串、数字或日期比较的内部比较函数。从 SortingCollator 类调用特定于区域设置(语言、地区和脚本)的比较方法,以执行字符串比较。此类使用区域设置样式来确定区域设置。请仅在需要自定义比较算法时指定自己的函数。这种情况通常仅当在显示中使用计算的字段时出现。

descending name null numeric null usingCustomCompareFunction