<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.
]]>Normalerweise wird die Sortierung für Sammlungen komplexer Elemente definiert, also für Sammlungen, in denen die Sortierung einer oder mehrerer Eigenschaften der Objekte in der Sammlung durchgeführt wird. Das folgende Beispiel veranschaulicht diese Verwendung:
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();
Es gibt Situationen, in denen die Sammlung einfache Elemente enthält, wie
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();
Die Flex-Implementierungen der
Der von der
<fx:Declarations> <s:SortField id="sf" /> </fx:Declarations>
<fx:Declarations> <s:SortField id="sf_SimplifiedChinese" locale="zh-Hans-CN" /> </fx:Declarations>
Erstellt eine neue Sort-Instanz ohne eingerichtete Felder und benutzerdefinierten Komparator.
<s:SpinnerList> <s:dataProvider> <s:NumericDataProvider minimum="0" maximum="23" stepSize="1"/> </s:dataProvider> </s:SpinnerList>
Der Vorteil dieser Klasse ist, dass die Elementwerte bei Bedarf berechnet anstatt gespeichert werden.
Beispiel: Wenn
<s:SortField>
tag has the following attributes:
<s:SortField Properties compareFunction="Internal compare function" descending="false" name="null" numeric="null" />]]>
Es gibt Situationen, in denen die Sammlung einfache Elemente enthält, wievar 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;
Der von der
<fx:Declarations> <s:SortField id="sf" /> </fx:Declarations>
<fx:Declarations> <s:SortField id="sf_SimplifiedChinese" locale="zh-Hans-CN" /> </fx:Declarations>
Die Vergleichsfunktion muss folgende Signatur haben:
Diese Funktion muss folgende Werte zurückgeben:
Der Standardwert ist eine interne Vergleichsfunktion, die einen Vergleich von Strings, numerischen Werten oder Datumsangaben in aufsteigender oder absteigender Reihenfolge durchführen kann. Der Stringvergleich wird mithilfe der gebietsschemaspezifischen (Sprache, Region und Skript) Vergleichsmethode aus der