<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.
]]>通常,这种排序是针对包含复杂项目的集合定义的,这样的集合是指那些对其中的对象的一个或多个属性执行排序的集合。以下示例显示了这种用法:
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();
也有集合中包含简单项目(如
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();
由
<fx:Declarations> <s:SortField id="sf" /> </fx:Declarations>
<fx:Declarations> <s:SortField id="sf_SimplifiedChinese" locale="zh-Hans-CN" /> </fx:Declarations>
创建一个不带字段集和自定义比较运算符的新 Sort。
<s:SpinnerList> <s:dataProvider> <s:NumericDataProvider minimum="0" maximum="23" stepSize="1"/> </s:dataProvider> </s:SpinnerList>
此类的优点是项值在需要时才计算,而不是存储项值。
例如,如果
<s:SortField>
tag has the following attributes:
<s:SortField Properties compareFunction="Internal compare function" descending="false" name="null" numeric="null" />]]>
也有集合中包含简单项目(如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;
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;
由
<fx:Declarations> <s:SortField id="sf" /> </fx:Declarations>
<fx:Declarations> <s:SortField id="sf_SimplifiedChinese" locale="zh-Hans-CN" /> </fx:Declarations>
该比较函数必须具有以下签名:
此函数必须返回以下值:
默认值为可以按升序或降序执行字符串、数字或日期比较的内部比较函数。从