패키지 | mx.collections |
클래스 | public class Sort |
상속 | Sort EventDispatcher Object |
구현 | ISort |
언어 버전: | ActionScript 3.0 |
제품 버전: | Flex 3 |
런타임 버전: | Flash Player 9, AIR 1.1 |
Flex 4.5(으)로 시작하는 경우 이 클래스 대신 spark.collections.Sort 클래스를 사용하는 것이 좋습니다. |
Provides the sorting information required to establish a sort on an existing view (ICollectionView interface or class that implements the interface). After you assign a Sort instance to the view's
sort
property, you must call the view's
refresh()
method to apply the sort criteria.
Typically the sort is defined for collections of complex items, that is
collections in which the sort is performed on one or more properties of
the objects in the collection.
The following example shows this use:
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:Sort = new Sort();
// Set the sort field; sort on the last name first, first name second.
// Both fields are case-insensitive.
sort.fields = [new SortField("last",true), new SortField("first",true)];
// Assign the Sort object to the view.
col.sort = sort;
// Apply the sort to the collection.
col.refresh();
There are situations in which the collection contains simple items,
like String
, Date
, Boolean
, etc.
In this case, apply the sort to the simple type directly.
When constructing a sort for simple items, use a single sort field,
and specify a null
name
(first) parameter
in the SortField object constructor.
For example:
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.
sort.fields = [new SortField(null, true)];
col.sort = sort;
col.refresh();
The Flex implementations of the ICollectionView interface retrieve all items from a remote location before executing a sort. If you use paging with a sorted list, apply the sort to the remote collection before you retrieve the data.
By default this Sort class does not provide correct language specific
sorting for strings. For this type of sorting please see the
spark.collections.Sort
and
spark.collections.SortField
classes.
The <mx:Sort>
tag has the following attributes:
<mx:Sort Properties compareFunction="Internal compare function" fields="null" unique="false | true" />
In case items have inconsistent data types or items have complex data types, the use of the default built-in compare functions is not recommended. Inconsistent sorting results may occur in such cases. To avoid such problem, provide a custom compare function and/or make the item types consistent.
Just like any other AdvancedStyleClient
-based classes,
the Sort
and SortField
classes do not have a
parent-child relationship in terms of event handling. Locale changes in a
Sort
instance are not dispatched to its SortField
instances automatically. The only exceptional case is the internal default
SortField
instance used when no explicit fields are provided.
In this case, the internal default SortField
instance follows
the locale style that the owner Sort
instance has.
기본 MXML 속성fields
관련 API 요소
속성 | 정의 주체 | ||
---|---|---|---|
compareFunction : Function
The method used to compare items when sorting. | Sort | ||
constructor : Object
지정된 객체 인스턴스의 클래스 객체 또는 생성자 함수에 대한 참조입니다. | Object | ||
fields : Array
An Array of ISortField objects that specifies the fields to compare. | Sort | ||
unique : Boolean
Indicates if the sort should be unique. | Sort |
메서드 | 정의 주체 | ||
---|---|---|---|
Sort()
Constructor. | Sort | ||
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
리스너에서 이벤트 알림을 받을 수 있도록 EventDispatcher 객체에 이벤트 리스너 객체를 등록합니다. | EventDispatcher | ||
이벤트를 이벤트 흐름으로 전달합니다. | EventDispatcher | ||
findItem(items:Array, values:Object, mode:String, returnInsertionIndex:Boolean = false, compareFunction:Function = null):int
Finds the specified object within the specified array (or the insertion
point if asked for), returning the index if found or -1 if not. | Sort | ||
EventDispatcher 객체에 특정 유형의 이벤트에 대한 리스너가 등록되어 있는지 여부를 확인합니다. | EventDispatcher | ||
지정된 속성이 객체에 정의되어 있는지 여부를 나타냅니다. | Object | ||
Object 클래스의 인스턴스가 매개 변수로 지정된 객체의 프로토타입 체인에 있는지 여부를 나타냅니다. | Object | ||
Return whether the specified property is used to control the sort. | Sort | ||
지정된 속성이 존재하고 열거 가능한지 여부를 나타냅니다. | Object | ||
EventDispatcher 객체에서 리스너를 제거합니다. | EventDispatcher | ||
Goes through the fields array and calls
reverse() on each of the ISortField objects in
the array. | Sort | ||
루프 작업에서 동적 속성을 사용할 수 있는지 여부를 설정합니다. | Object | ||
Apply the current sort to the specified array (not a copy). | Sort | ||
로캘별 규칙에 따라 서식이 지정된 이 객체의 문자열 표현을 반환합니다. | Object | ||
지정된 객체의 문자열 표현을 반환합니다. | Object | ||
지정된 객체의 프리미티브 값을 반환합니다. | Object | ||
이 EventDispatcher 객체 또는 조상 객체에 지정한 이벤트 유형에 대한 이벤트 리스너가 등록되어 있는지 여부를 확인합니다. | EventDispatcher |
상수 | 정의 주체 | ||
---|---|---|---|
ANY_INDEX_MODE : String = "any" [정적]
When executing a find return the index any matching item. | Sort | ||
FIRST_INDEX_MODE : String = "first" [정적]
When executing a find return the index for the first matching item. | Sort | ||
LAST_INDEX_MODE : String = "last" [정적]
When executing a find return the index for the last matching item. | Sort |
compareFunction | 속성 |
compareFunction:Function
언어 버전: | ActionScript 3.0 |
제품 버전: | Flex 3 |
런타임 버전: | Flash Player 9, AIR 1.1 |
The method used to compare items when sorting.
If you specify this property, Flex ignores any
compareFunction
properties that you specify in the
ISortField
objects that you use in this class.
The compare function must have the following signature:
function [name](a:Object, b:Object, fields:Array = null):int
This function must return the following value:
- -1, if the
Object a
should appear before theObject b
in the sorted sequence - 0, if the
Object a
equals theObject b
- 1, if the
Object a
should appear after theObject b
in the sorted sequence
To return to the internal comparision function, set this value to
null
.
The fields
array specifies the object fields
to compare.
Typically the algorithm will compare properties until the field list is
exhausted or a non-zero value can be returned.
For example:
function myCompare(a:Object, b:Object, fields:Array = null):int
{
var result:int = 0;
var i:int = 0;
var propList:Array = fields ? fields : internalPropList;
var len:int = propList.length;
var propName:String;
while (result == 0 && (i < len))
{
propName = propList[i];
result = compareValues(a[propName], b[propName]);
i++;
}
return result;
}
function compareValues(a:Object, b:Object):int
{
if (a == null && b == null)
return 0;
if (a == null)
return 1;
if (b == null)
return -1;
if (a < b)
return -1;
if (a > b)
return 1;
return 0;
}
The default value is an internal compare function that can perform a string, numeric, or date comparison in ascending or descending order. Specify your own function only if you need a need a custom comparison algorithm. This is normally only the case if a calculated field is used in a display.
Alternatively you can specify separate compare functions for each
sort field by using the ISortField
class
compareFunction
property; This way you can use the default
comparison for some fields and a custom comparison for others.
구현
public function get compareFunction():Function
public function set compareFunction(value:Function):void
fields | 속성 |
fields:Array
언어 버전: | ActionScript 3.0 |
제품 버전: | Flex 3 |
런타임 버전: | Flash Player 9, AIR 1.1 |
An Array
of ISortField
objects that specifies the fields to compare.
The order of the ISortField objects in the array determines
field priority order when sorting.
The default sort comparator checks the sort fields in array
order until it determinines a sort order for the two
fields being compared.
기본값: null.
이 속성은 데이터 바인딩에 대한 소스로 사용할 수 있습니다. 이 속성을 수정하면 fieldsChanged
이벤트를 전달합니다.
구현
public function get fields():Array
public function set fields(value:Array):void
관련 API 요소
unique | 속성 |
unique:Boolean
언어 버전: | ActionScript 3.0 |
제품 버전: | Flex 3 |
런타임 버전: | Flash Player 9, AIR 1.1 |
Indicates if the sort should be unique.
Unique sorts fail if any value or combined value specified by the
fields listed in the fields property result in an indeterminate or
non-unique sort order; that is, if two or more items have identical
sort field values. An error is thrown if the sort is not unique.
The sorting logic uses this unique
property value only if sort
field(s) are specified explicitly. If no sort fields are specified
explicitly, no error is thrown even when there are identical value
elements.
기본값: false.
구현
public function get unique():Boolean
public function set unique(value:Boolean):void
Sort | () | 생성자 |
public function Sort()
언어 버전: | ActionScript 3.0 |
제품 버전: | Flex 3 |
런타임 버전: | Flash Player 9, AIR 1.1 |
Constructor.
Creates a new Sort with no fields set and no custom comparator.
findItem | () | 메서드 |
public function findItem(items:Array, values:Object, mode:String, returnInsertionIndex:Boolean = false, compareFunction:Function = null):int
언어 버전: | ActionScript 3.0 |
제품 버전: | Flex 3 |
런타임 버전: | Flash Player 9, AIR 1.1 |
Finds the specified object within the specified array (or the insertion
point if asked for), returning the index if found or -1 if not.
The ListCollectionView
class findxxx()
methods use this method to find the requested item; as a general rule,
it is easier to use these functions, and not findItem()
to find data in ListCollectionView
-based objects.
You call the findItem()
method directly when writing a
class that supports sorting, such as a new ICollectionView
implementation.
The input items array need to be sorted before calling this function.
Otherwise this function will not be able to find the specified value
properly.
매개 변수
items:Array — the Array within which to search.
| |||||||
values:Object — Object containing the properties to look for (or
the object to search for, itself).
The object must consist of field name/value pairs, where
the field names are names of fields specified by the
fields property, in the same order they
are used in that property.
You do not have to specify all of the fields from the
fields property, but you
cannot skip any in the order.
Therefore, if the fields
properity lists three fields, you can specify its first
and second fields in this parameter, but you cannot
specify only the first and third fields.
| |||||||
mode:String — String containing the type of find to perform.
Valid values are:
| |||||||
returnInsertionIndex:Boolean (default = false ) — If the method does not find an item
identified by the values parameter,
and this parameter is true the
findItem()
method returns the insertion point for the values,
that is the point in the sorted order where you
should insert the item.
| |||||||
compareFunction:Function (default = null ) — a comparator function to use to find the item.
If you do not specify this parameter or , or if you
provide a null value,
findItem() function uses the
compare function determined by the ISort
instance's compareFunction property,
passing in the array of fields determined
by the values object and the current
SortFields .
If you provide a non-null value, findItem()
function uses it as the compare function.
The signature of the function passed as
compareFunction must be as follows:
function myCompareFunction(a:Object, b:Object):int .
Note that there is no third argument unlike the
compare function for ISort.compareFunction()
property.
|
int — int The index in the array of the found item.
If the returnInsertionIndex parameter is
false and the item is not found, returns -1.
If the returnInsertionIndex parameter is
true and the item is not found, returns
the index of the point in the sorted array where the
values would be inserted.
|
propertyAffectsSort | () | 메서드 |
public function propertyAffectsSort(property:String):Boolean
언어 버전: | ActionScript 3.0 |
제품 버전: | Flex 3 |
런타임 버전: | Flash Player 9, AIR 1.1 |
Return whether the specified property is used to control the sort.
The function cannot determine a definitive answer if the sort uses a
custom comparator; it always returns true
in this case.
매개 변수
property:String — The name of the field that to test.
|
Boolean — Whether the property value might affect the sort outcome.
If the sort uses the default compareFunction, returns
true if the
property parameter specifies a sort field.
If the sort or any ISortField uses a custom comparator,
there's no way to know, so return true .
|
reverse | () | 메서드 |
public function reverse():void
언어 버전: | ActionScript 3.0 |
제품 버전: | Flex 3 |
런타임 버전: | Flash Player 9, AIR 1.1 |
Goes through the fields
array and calls
reverse()
on each of the ISortField
objects in
the array. If the field was descending now it is ascending,
and vice versa.
Note: an ICollectionView
does not automatically
update when the objects in the fields
array are modified;
call its refresh()
method to update the view.
sort | () | 메서드 |
public function sort(items:Array):void
언어 버전: | ActionScript 3.0 |
제품 버전: | Flex 3 |
런타임 버전: | Flash Player 9, AIR 1.1 |
Apply the current sort to the specified array (not a copy).
To prevent the array from being modified, create a copy
use the copy in the items
parameter.
Flex ICollectionView
implementations call the
sort
method automatically and ensure that the sort is
performed on a copy of the underlying data.
매개 변수
items:Array — Array of items to sort.
|
ANY_INDEX_MODE | 상수 |
public static const ANY_INDEX_MODE:String = "any"
언어 버전: | ActionScript 3.0 |
제품 버전: | Flex 3 |
런타임 버전: | Flash Player 9, AIR 1.1 |
When executing a find return the index any matching item.
FIRST_INDEX_MODE | 상수 |
public static const FIRST_INDEX_MODE:String = "first"
언어 버전: | ActionScript 3.0 |
제품 버전: | Flex 3 |
런타임 버전: | Flash Player 9, AIR 1.1 |
When executing a find return the index for the first matching item.
LAST_INDEX_MODE | 상수 |
public static const LAST_INDEX_MODE:String = "last"
언어 버전: | ActionScript 3.0 |
제품 버전: | Flex 3 |
런타임 버전: | Flash Player 9, AIR 1.1 |
When executing a find return the index for the last matching item.
Tue Jun 12 2018, 03:17 PM Z