<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>
フィールドを設定しない、カスタムコンパレータのない新しいソートを作成します。
<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>
比較関数には次のシグネチャが必要です。
この関数では、次の値が返される必要があります。
デフォルト値は、ストリング、数値、日付を比較できる内部比較関数です。この比較関数では、昇順または降順での比較が可能です。 ストリングの比較は、