Flex中利用SortField和Sort类对ArrayCollection进行排序的例子
2015-04-02 14:12
453 查看
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
backgroundColor="white"
creationComplete="init()">
<fx:Script>
<![CDATA[
import mx.collections.SortField;
import mx.collections.Sort;
import mx.collections.ArrayCollection;
[Bindable]
private var arrColl:ArrayCollection;
/** This method gets called by the main mx:Application tag and initializes/populates the ArrayCollection object with a bunch of random numbers. */
private function init():void
{
var i:int;
/* Initialize and populate the ArrayCollection object. */
arrColl=new ArrayCollection();
for (i=0; i < 20; i++)
{
arrColl.addItem({data: getRandomNumber().toFixed(4)});
}
}
/** This method returns a random floating-point number between 0 and 10000. */
private function getRandomNumber():Number
{
return Math.random() * 10000;
}
/** This method gets called by the Button control's click handler and creates a new SortField and Sort object which are used to sort the ArrayCollection. */
private function button_click():void
{
/* Create the SortField object for
the "data" field in the ArrayCollection
object, and make sure we do a numeric sort.
*/
var dataSortField:SortField=new SortField();
dataSortField.name="data";
dataSortField.numeric=true;
/* Create the Sort object and add the
SortField object created earlier to the
array of fields to sort on. */
var numericDataSort:Sort=new Sort();
numericDataSort.fields=[dataSortField];
/* Set the ArrayCollection object's
sort property to our custom sort,
and refresh the ArrayCollection. */
arrColl.sort=numericDataSort;
arrColl.refresh();
}
]]>
</fx:Script>
<mx:List id="list"
dataProvider="{arrColl}"
textAlign="right"
labelField="data"
width="300"/>
<mx:Button id="button"
x = "200" y="400"
label="sort items"
click="button_click()"/>
</s:Application>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
backgroundColor="white"
creationComplete="init()">
<fx:Script>
<![CDATA[
import mx.collections.SortField;
import mx.collections.Sort;
import mx.collections.ArrayCollection;
[Bindable]
private var arrColl:ArrayCollection;
/** This method gets called by the main mx:Application tag and initializes/populates the ArrayCollection object with a bunch of random numbers. */
private function init():void
{
var i:int;
/* Initialize and populate the ArrayCollection object. */
arrColl=new ArrayCollection();
for (i=0; i < 20; i++)
{
arrColl.addItem({data: getRandomNumber().toFixed(4)});
}
}
/** This method returns a random floating-point number between 0 and 10000. */
private function getRandomNumber():Number
{
return Math.random() * 10000;
}
/** This method gets called by the Button control's click handler and creates a new SortField and Sort object which are used to sort the ArrayCollection. */
private function button_click():void
{
/* Create the SortField object for
the "data" field in the ArrayCollection
object, and make sure we do a numeric sort.
*/
var dataSortField:SortField=new SortField();
dataSortField.name="data";
dataSortField.numeric=true;
/* Create the Sort object and add the
SortField object created earlier to the
array of fields to sort on. */
var numericDataSort:Sort=new Sort();
numericDataSort.fields=[dataSortField];
/* Set the ArrayCollection object's
sort property to our custom sort,
and refresh the ArrayCollection. */
arrColl.sort=numericDataSort;
arrColl.refresh();
}
]]>
</fx:Script>
<mx:List id="list"
dataProvider="{arrColl}"
textAlign="right"
labelField="data"
width="300"/>
<mx:Button id="button"
x = "200" y="400"
label="sort items"
click="button_click()"/>
</s:Application>
相关文章推荐
- Flex中利用CheckBox对DataGrid控件中的项目进行过滤的例子
- 利用Collator和Collections.sort对list进行中文排序,注意与Arrays.sort的区别
- LinkedList中将对象按照某一属性排序,利用 collection.sort(); 来进行调用!
- 利用 Arrays.sort 字符串 进行排序 完全按字符 排序 忽略字符大小写
- C# 利用list.sort()进行排序
- Flex中如何利用getTextField事件和numLines属性,计算出TextArea控件中内容的行数的例子
- 利用Arrays.sort(Array,Comparator)对数组进行排序
- Android利用Collections.sort()对Map里的键值对按照键进行排序,让listview按序显示
- 利用sort进行排序
- .net 利用array.sort对结构数组进行排序
- Flex中如何利用Matrix类的rotate函数对图片进行旋转操作的例子
- 排序例子2:使用sort()方法对数组进行排序
- javascript 利用Array的sort方法,对Array进行排序 (Array里面放的是对象而不是字符串)
- Flex中如何利用focusIn和focusOut事件对表单中获得焦点的项目进行颜色高亮(highlight)显示的例子
- 利用 Arrays.sort 字符串 进行排序 完全按字符 排序 忽略字符大小写
- Flex中如何利用Matrix类的rotate函数对图片进行旋转操作的例子
- 利用sort对数组进行自定义排序
- 关于利用STL中的sort算法对向量等容器进行排序的问题
- 利用STL中的sort算法对向量等容器进行排序
- 利用SortFilterModel来对我们的Model进行过滤及排序