Flex4.6 ArrayCollection求最大值,最小值,排序

                        Flex 4.6    ArrayCollection求最大值,最小值,排序

 项目需求:求出ArrayCollection的最大值,最小值,排序

 源代码下载地址:http://download.csdn.net/detail/wuxiaokaixinguo/5290274

代码如下:

<?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" minWidth="955" minHeight="600">
	<fx:Declarations>
		<!-- 将非可视元素(例如服务、值对象)放在此处 -->
	</fx:Declarations>
	<fx:Script>
		<![CDATA[
			import mx.collections.ArrayCollection;
			import mx.collections.Sort;
			import mx.collections.SortField;
			import mx.controls.Alert;
			
			[Bindable]
			public var coll:ArrayCollection = new ArrayCollection([
				{getInfoTime:'2013-04-23 10:00',waterHeight:6},
				{getInfoTime:'2013-04-23 10:02',waterHeight:2},
				{getInfoTime:'2013-04-23 10:04',waterHeight:3},
				{getInfoTime:'2013-04-23 10:06',waterHeight:1000},
				{getInfoTime:'2013-04-23 10:08',waterHeight:5.0},
				{getInfoTime:'2013-04-23 10:10',waterHeight:2000}
			  ]);
			// Get a function of the maximum
			public function btn_getMaxValue_clickHandler():void{
				var sort:Sort = new Sort();
				//按照waterHeight升序排序
				sort.fields=[new SortField("waterHeight")];  
				coll.sort = sort;
				coll.refresh();
				Alert.show(coll[coll.length-1].waterHeight);
			}
			
			//Get a function of the minimum
			public function btn_getMinValue_clickHandler():void{
				var sort:Sort = new Sort();
				//按照waterHeight升序排序
				sort.fields=[new SortField("waterHeight")];  
				coll.sort = sort;
				coll.refresh();
				Alert.show(coll[0].waterHeight);
				
			}
		]]>
	</fx:Script>
	<s:Button x="171" y="156" width="83" height="31" label="获取最大值" click="btn_getMaxValue_clickHandler();"/>
	<s:Button x="321" y="157" width="83" height="31" label="获取最小值" click="btn_getMinValue_clickHandler();"/>
	
</s:Application>

备用知识:

SortField的用法:

构造函数细节

SortField () 构造函数 

public function SortField(name:String = null, caseInsensitive:Boolean = false, descending:Boolean = false, numeric:Object = null)

构造函数。 

参数  name:String (default = null) — 此字段用来进行比较的属性的名称。如果该对象为简单类型,则传递 null。  

 caseInsensitive:Boolean (default = false) — 在对字符串进行排序时,指示比较运算符是否忽略值的大小写。  

 descending:Boolean (default = false) — 指示比较运算符是否按降序排列项目。  

 numeric:Object (default = null) — 指示比较运算符是否按编号而不按字母顺序比较排序项目。  


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值