码迷,mamicode.com
首页 > 其他好文 > 详细

ArrayCollection 获取最大值和获取最小值

时间:2015-01-18 17:03:22      阅读:218      评论:0      收藏:0      [点我收藏+]

标签:

ArrayCollection 获取最大值和获取最小值

<?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>

 

ArrayCollection 获取最大值和获取最小值

标签:

原文地址:http://www.cnblogs.com/uje188/p/4231929.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!