zoukankan      html  css  js  c++  java
  • Flex 对ArrayCollection的重构

    由于项目的需要,对ArrayCollection进行重构,包括如下功能:
    1,排序
    2,moveFirst moveLast moveNext movePre 进行记录导航 和选择某个index的对象
    3,删除,更新,插入,添加记录的功能
    4,过滤
    以下是例子:

    Java代码 复制代码 收藏代码

    1. <?xml version="1.0" encoding="utf-8"?>  
    2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init();">  
    3. <mx:Script>  
    4.     <![CDATA[  
    5. import mx.collections.CursorBookmark;  
    6. import com.hexagonstar.util.debug.Debug;  
    7. import org.app.utils.common.collections.MyArrayCollection;  
    8. import com.adobe.serialization.json.JSON;  
    9.         var arr:Array=[  
    10.             {a:1,b:1,c:1},  
    11.             {a:21,b:21,c:21},  
    12.             {a:12,b:12,c:12},  
    13.             {a:10,b:10,c:10},  
    14.             {a:2,b:2,c:2}  
    15.             ];  
    16.         [Bindable]  
    17.         var coll:MyArrayCollection = null;  
    18.         [Bindable]  
    19.         var scc:String = null;  
    20. private function init():void{  
    21.             coll =new MyArrayCollection(arr);  
    22. //var sortArr:Array=[{name:"a"},{name:"b"}];
    23. //coll.sortCollection(sortArr);
    24.             src.text= coll.toString();  
    25. //dest.text = JSON.encode(coll.currentItem);
    26.             scc = coll.toString();  
    27.             dest.text = scc;  
    28. //keywords
    29.             coll.keywords=["a"];  
    30.         }  
    31. private function insert():void{  
    32.             var s:String = src.text;  
    33.             var o:Object = JSON.decode(s);  
    34.             coll.insertItem(o);  
    35.             scc = coll.toString();  
    36.             dest.text = scc;  
    37.         }  
    38. private function append():void{  
    39.             var s:String = src.text;  
    40.             var o:Object = JSON.decode(s);  
    41.             coll.appendItem(o);  
    42.             scc = coll.toString();  
    43.             dest.text = scc;  
    44.         }  
    45. private function moveFirst():void{  
    46.             var o:Object = coll.moveFirst();  
    47.             dest.text = JSON.encode(o);  
    48.         }  
    49. private function moveLast():void{  
    50.             var o:Object = coll.moveLast();  
    51.             dest.text = JSON.encode(o);  
    52.         }  
    53. private function moveNext():void{  
    54.             var o:Object = coll.moveNext();  
    55.             dest.text = JSON.encode(o);  
    56.         }  
    57. private function movePre():void{  
    58.             var o:Object = coll.movePrevious();  
    59.             dest.text = JSON.encode(o);  
    60.         }  
    61. private function doClear():void{  
    62.             dest.text = "";  
    63.         }  
    64. private function doUpd():void{  
    65.             var o:Object = JSON.decode(src.text);  
    66.             coll.updateItem(o);  
    67.             o = coll.currentItem;  
    68.             dest.text = JSON.encode(o);  
    69.         }  
    70. private function doDel():void{  
    71.             var o:Object = JSON.decode(src.text);  
    72.             var flg:Boolean = coll.remove();  
    73.             Debug.trace("--remove:"+flg);  
    74.             scc = coll.toString();  
    75.             dest.text = scc;  
    76.         }  
    77.     ]]>  
    78. </mx:Script>  
    79.     <mx:TextArea id="src" x="25" y="40" width="267" height="103"/>  
    80.     <mx:Button x="25" y="10" label="更新" click="doUpd();"/>  
    81.     <mx:Button x="188" y="10" label="删除" click="doDel();"/>  
    82.     <mx:Button x="244" y="10" label="排序"/>  
    83.     <mx:Button x="76" y="10" label="插入" click="insert();"/>  
    84.     <mx:Button x="132" y="10" label="添加" click="append();"/>  
    85.     <mx:TextArea id="dest" x="300" y="40" width="333" height="103" editable="false" text="{scc}"/>  
    86.     <mx:Button x="25" y="299" label="|&lt;" toolTip="第一个" click="moveFirst();"/>  
    87.     <mx:Button x="125" y="299" label="&gt;&gt;" toolTip="后一个" click="moveNext();"/>  
    88.     <mx:Button x="73" y="299" label="&lt;&lt;" toolTip="前一个" click="movePre();"/>  
    89.     <mx:Button x="177" y="299" label="&gt;|" toolTip="最后一个" click="moveLast();"/>  
    90.     <mx:DataGrid x="25" y="151" width="608" height="143" dataProvider="{coll}">  
    91.         <mx:columns>  
    92.             <mx:DataGridColumn headerText="ColumnA" dataField="a"/>  
    93.             <mx:DataGridColumn headerText="ColumnB" dataField="b"/>  
    94.             <mx:DataGridColumn headerText="ColumnC" dataField="c"/>  
    95.         </mx:columns>  
    96.     </mx:DataGrid>  
    97.     <mx:Button x="585" y="10" label="清空" toggle="true" click="doClear();"/>  
    98. </mx:Application> 
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init();">
    <mx:Script>
    	<![CDATA[
    		import mx.collections.CursorBookmark;
    		import com.hexagonstar.util.debug.Debug;
    		import org.app.utils.common.collections.MyArrayCollection;
    		import com.adobe.serialization.json.JSON;
    		var arr:Array=[
    			{a:1,b:1,c:1},
    			{a:21,b:21,c:21},
    			{a:12,b:12,c:12},
    			{a:10,b:10,c:10},
    			{a:2,b:2,c:2}
    			];
    		[Bindable]
    		var coll:MyArrayCollection = null;
    		[Bindable]
    		var scc:String = null;
    		private function init():void{
    			coll =new MyArrayCollection(arr);
    			//var sortArr:Array=[{name:"a"},{name:"b"}];
    			//coll.sortCollection(sortArr);
    			src.text= coll.toString();
    			//dest.text = JSON.encode(coll.currentItem);
    			scc = coll.toString();
    			dest.text = scc;
    			//keywords
    			coll.keywords=["a"];
    		}
    		
    		private function insert():void{
    			var s:String = src.text;
    			var o:Object = JSON.decode(s);
    			coll.insertItem(o);
    			scc = coll.toString();
    			dest.text = scc;
    		}
    		private function append():void{
    			var s:String = src.text;
    			var o:Object = JSON.decode(s);
    			coll.appendItem(o);
    			scc = coll.toString();
    			dest.text = scc;
    		}
    		private function moveFirst():void{
    			var o:Object = coll.moveFirst();
    			dest.text = JSON.encode(o);
    		}
    		private function moveLast():void{
    			var o:Object = coll.moveLast();
    			dest.text = JSON.encode(o);
    		}
    		private function moveNext():void{
    			var o:Object = coll.moveNext();
    			dest.text = JSON.encode(o);
    		}
    		private function movePre():void{
    			var o:Object = coll.movePrevious();
    			dest.text = JSON.encode(o);
    		}
    		private function doClear():void{
    			dest.text = "";
    		}
    		private function doUpd():void{
    			var o:Object = JSON.decode(src.text);
    			coll.updateItem(o);
    			o = coll.currentItem;
    			dest.text = JSON.encode(o);
    		}
    		private function doDel():void{
    			var o:Object = JSON.decode(src.text);
    			var flg:Boolean = coll.remove();
    			Debug.trace("--remove:"+flg);
    			scc = coll.toString();
    			dest.text = scc;
    		}
    	]]>
    </mx:Script>
    	<mx:TextArea id="src" x="25" y="40" width="267" height="103"/>
    	<mx:Button x="25" y="10" label="更新" click="doUpd();"/>
    	<mx:Button x="188" y="10" label="删除" click="doDel();"/>
    	<mx:Button x="244" y="10" label="排序"/>
    	<mx:Button x="76" y="10" label="插入" click="insert();"/>
    	<mx:Button x="132" y="10" label="添加" click="append();"/>
    	<mx:TextArea id="dest" x="300" y="40" width="333" height="103" editable="false" text="{scc}"/>
    	<mx:Button x="25" y="299" label="|&lt;" toolTip="第一个" click="moveFirst();"/>
    	<mx:Button x="125" y="299" label="&gt;&gt;" toolTip="后一个" click="moveNext();"/>
    	<mx:Button x="73" y="299" label="&lt;&lt;" toolTip="前一个" click="movePre();"/>
    	<mx:Button x="177" y="299" label="&gt;|" toolTip="最后一个" click="moveLast();"/>
    	<mx:DataGrid x="25" y="151" width="608" height="143" dataProvider="{coll}">
    		<mx:columns>
    			<mx:DataGridColumn headerText="ColumnA" dataField="a"/>
    			<mx:DataGridColumn headerText="ColumnB" dataField="b"/>
    			<mx:DataGridColumn headerText="ColumnC" dataField="c"/>
    		</mx:columns>
    	</mx:DataGrid>
    	<mx:Button x="585" y="10" label="清空" toggle="true" click="doClear();"/>
    </mx:Application>

    以下是源码:

    Java代码 复制代码 收藏代码

    1. /**
    2. * 用法:
    3. * coll=new ArrayCollection(
    4. *          [
    5. *           {name: "Martin Foo", age: 25}, 
    6. *           {name: "Joe Bar", age: 15}, 
    7. *           {name: "John Baz", age: 23}
    8. *          ]
    9. * );
    10. * coll.addItemAt({name: "James Fez", age: 40}, 0);
    11. */
    12. package org.app.utils.common.collections  
    13. {     
    14. import flash.events.Event;  
    15. import mx.collections.ArrayCollection;  
    16. import mx.collections.CursorBookmark;  
    17. import mx.collections.IViewCursor;  
    18. import mx.collections.Sort;  
    19. import mx.collections.SortField;  
    20. import mx.events.FlexEvent;  
    21. import mx.logging.ILogger;  
    22. import org.app.framework.AppContext;  
    23. import org.app.utils.common.MyJSONUtils;  
    24. import org.app.utils.log.MyLoggerManager;  
    25. public class MyArrayCollection extends ArrayCollection  
    26.     {  
    27. ////////////////////////////////////////////////////////////////////////
    28. /*排序规则参数*/
    29. public static const RL_NAME:String = "name";//要排序的字段的名称。[String]
    30. public static const RL_CASEINSENSITIVE:String = "caseInsensitive";//Boolean 指定此字段的排序是否应不区分大小写。
    31. public static const RL_DESCENDING:String = "descending";//Boolean 指定此字段是否应按降序排序。
    32. /*事件相关*/
    33. //光标位置更新时的事件
    34. public static const EVENT_CURSOR_UPDATE:String = "event_cursor_update";  
    35. /*Object 指定当要进行排序的字段包含数值 (number/int/uint) 
    36.          * 或数值的字符串表示形式时,比较运算符是否使用数值比较。*/
    37. public static const RL_NUMERIC:String = "numeric";  
    38. ////////////////////////////////////////////////////////////////////////
    39. private var logger:ILogger = MyLoggerManager.getLogger("MyArrayCollection",AppContext.getInstance().appLogTarget);  
    40. ////////////////////////////////////////////////////////////////////////
    41. /*游标*/
    42. private var _cursor:IViewCursor = null;//当前游标
    43. private var _currentItem:Object = null;//当前游标指向对象
    44. /*如果是JSON对象,那么有keys*/
    45. private var _keys:Array = null;//该数组包含的json properties
    46. private var _keywords:Array = null;//哪些properties是主键,用于判断重复
    47. public function MyArrayCollection(source:Array=null)  
    48.         {  
    49. super(source);  
    50. //取得当前的光标对象
    51. this._cursor = this.createCursor();  
    52. //注册光标位置更新事件
    53. this._cursor.addEventListener(FlexEvent.CURSOR_UPDATE,fireCursorUpdate,false,0,true);  
    54. //給当前光标对象赋值--就会触发cursor update事件
    55. this._cursor.seek(CursorBookmark.CURRENT);  
    56. //初始化keys 或者 获取keys
    57. this.fetchKeys();  
    58.         }  
    59. ////////////////////////////////////////////////////////////////////////
    60. /**
    61.          * 当光标位置更新时触发的事件,在这取得当前光标位置的值,
    62.          * 其他地方光标移动时不要給 currentItem赋值了。
    63.          * @param FlexEvent
    64.          * @return
    65.          */
    66. private function fireCursorUpdate(event:FlexEvent):void{  
    67. //取得当前的值
    68. this._currentItem = (event.currentTarget as IViewCursor).current;  
    69. //防止 moveLast moveFirst抛出多2个事件,只有当前有对象值了,才抛出
    70.             var a:String = "不抛出";  
    71. if (this._currentItem) {  
    72.                 a="抛出";  
    73. this.dispatchEvent(new Event(EVENT_CURSOR_UPDATE));  
    74.             }  
    75.             var s:String = MyJSONUtils.encode(this._currentItem);  
    76.             logger.debug("--触发了 cursor update 事件,当前对象:"+s+"["+a+"]");  
    77.         }  
    78. ////////////////////////////////////////////////////////////////////////
    79. ////////////////////////////////////////////////////////////////////////
    80. public function set cursor(cursor:IViewCursor):void{  
    81. this._cursor = cursor;  
    82.         }  
    83. public function get cursor():IViewCursor{  
    84. return this._cursor;  
    85.         }  
    86. public function set currentItem(o:Object):void{  
    87. //替换掉当前对象里面的值
    88. this.updateItem(o);  
    89. //this._currentItem = o;
    90.         }  
    91. public function get currentItem():Object{  
    92. return this._currentItem;  
    93.         }  
    94. ////////////////////////////////////////////////////////////////////////
    95. public function fetchKeys():void{  
    96. if(this.length>0){  
    97.                 var o:Object = this.getItemAt(0);  
    98. this._keys = MyJSONUtils.fetchKeys(o);  
    99.             }else{  
    100. this._keys = [];  
    101.             }  
    102.         }  
    103. public function getKeys():Array{  
    104. if(this._keys.length<=0){  
    105. this.fetchKeys();  
    106.             }  
    107. return this._keys;  
    108.         }  
    109. public function set keywords(k:Array):void{  
    110. this._keywords = k;  
    111.         }  
    112. public function get keywords():Array{  
    113. return this._keywords;  
    114.         }  
    115. ////////////////////////////////////////////////////////////////////////
    116. ////////////////////////////////////////////////////////////////////////
    117. /**
    118.          * 检查是否存在某个条件的对象??????
    119.          * @param Object  json object eg:{name:"xxx_name", age:34 .....}
    120.          * @param String 比较类型 采用Sort里面引用的常量
    121.          * @return int 存在的个数
    122.          * 
    123.          * @see mx.collections.Sort
    124.          */
    125. public function checkExist(conditionObj:Object,mode:String=Sort.ANY_INDEX_MODE):int{  
    126.             var sort:Sort = new Sort();  
    127. return sort.findItem(this.source,conditionObj,mode);     
    128.         }  
    129. /**
    130.          * [这个比较 很慢]
    131.          * 检查是否存在某个对象,其中keys指根据哪些key进行比较,如果为空,那么根据全部key来比
    132.          * @param Object
    133.          * @param Array 要比较的key
    134.          * @return Boolean true存在
    135.          */
    136. public function isExist(o:Object,keys:Array=null):Boolean{  
    137.             var key1:Array = keys;  
    138. if(key1==null){  
    139.                 key1 = MyJSONUtils.fetchKeys(o);  
    140.             }  
    141.             var item1:String = null;  
    142.             var l:int=key1.length;  
    143. for each(var obj:Object in this){  
    144.                 var flg:int = 0;  
    145. for(var i:int=0;i<l;i++){  
    146.                     item1=key1[i];  
    147. if(o[item1]==obj[item1]){  
    148.                         flg++;  
    149.                     }  
    150.                 }  
    151. if(flg==l)return true;  
    152.             }  
    153. return false;  
    154.         }  
    155. /**
    156.          * 覆盖该方法,来做重复检查
    157.          * @param Object 要比较的对象
    158.          * @return Boolean true存在
    159.          */
    160.         override public function contains(item:Object):Boolean{  
    161. return isExist(item,this._keywords);  
    162.         }  
    163. ////////////////////////////////////////////////////////////////////////
    164. /**
    165.          * 按照一定的规则排序,可以多个字段同时排序:
    166.          * -- name : String 要排序的字段的名称。 
    167.          * -- caseInsensitive : Boolean 指定此字段的排序是否应不区分大小写。 
    168.          * -- descending : Boolean 指定此字段是否应按降序排序。
    169.          * -- numeric : Object 指定当要进行排序的字段包含数值 (number/int/uint) 
    170.          *              或数值的字符串表示形式时,比较运算符是否使用数值比较。 
    171.          * eg:[{name:'age',caseInsensitive:true,descending:false,numeric:null},
    172.          *                   {name:'age',descending:false}...]
    173.          *   是个数组,而且 里面是json对象,包含四个元素:name,caseInsensitive,descending,numeric,
    174.          *   其中,name是必须的,其他的可选。
    175.          * @param Object 类似上面的写
    176.          * @return
    177.          * @see mx.colloections.SortField
    178.          * 
    179.          */
    180. public function sortCollection(conditionObj:Array):void{  
    181.             var leng:int = conditionObj.length;  
    182.             var fields:Array = [];  
    183.             var sortField:SortField = null;  
    184.             var o:Object=null;  
    185.             var name:String=null;  
    186.             var caseInsensitive:Boolean=false;  
    187.             var descending:Boolean = false;  
    188.             var numeric:Object = null;  
    189. for(var i:int=0;i<leng;i++){  
    190.                 o = conditionObj[i];  
    191.                 sortField = new SortField();  
    192. //加入参数
    193.                 sortField.name=o[MyArrayCollection.RL_NAME];  
    194.                 var tmp:Object = o[MyArrayCollection.RL_CASEINSENSITIVE];  
    195.                 caseInsensitive=tmp==null?false:true;  
    196.                 sortField.caseInsensitive=caseInsensitive;  
    197.                 tmp = o[MyArrayCollection.RL_DESCENDING];  
    198.                 descending=tmp==null?false:true;  
    199.                 sortField.descending=descending;  
    200.                 tmp = o[MyArrayCollection.RL_NUMERIC];  
    201.                 numeric=tmp==null?null:tmp;  
    202.                 sortField.numeric=numeric;  
    203. //加入比较器
    204.                 fields.push(sortField);  
    205.             }  
    206.             var sort:Sort = new Sort();  
    207.             sort.fields=fields;  
    208. this.sort = sort;  
    209. this.refresh();  
    210.         }  
    211. ////////////////////////////////////////////////////////////////////////
    212. /**
    213.          * 过滤,首先必须知道自己要过滤的集合里面有些什么字段,
    214.          * coll = new ArrayCollection([
    215.          *                      {name:"Martin Foo", age:25},      
    216.          *                      {name:"Joe Bar", age:15},      
    217.          *                      {name:"John Baz", age:23},      
    218.          *                      {name:"Matt Baz", age:21}]);
    219.          * 那么func:
    220.          * private function filterFunc(value:Object):Object {      
    221.         *  if(Number(value.age) > 21) {      
    222.       *    return true;      
    223.         *  }
    224.         *  return false;      
    225.          *} 
    226.          * @param Function 如上
    227.          * @return
    228.          */
    229. public function filterCollection(filterFunc:Function):void{  
    230. this.filterFunction = filterFunc;  
    231. this.refresh();  
    232.         }  
    233. ////////////////////////////////////////////////////////////////////////
    234. ////////////////////////////////////////////////////////////////////////
    235. ////////////////////////////////////////////////////////////////////////
    236. /**
    237.          * 取得第一个对象,根据cursorMove 来判断是否移动光标
    238.          * @param Boolean 是否移动当前光标
    239.          * @return Object 第一个位置的对象
    240.          */
    241. public function firstItem(cursorMove:Boolean=true):Object{  
    242. if(cursorMove){  
    243. return this.moveFirst();  
    244.             }  
    245. return this.getItemAt(0);  
    246.         }  
    247. /**
    248.          * 取得最后一个对象,根据cursorMove 来判断是否移动光标
    249.          * @param Boolean 是否移动当前光标
    250.          * @return Object 最后一个位置的对象
    251.          */
    252. public function lastItem(cursorMove:Boolean=true):Object{  
    253. if(cursorMove){  
    254. return this.moveLast();  
    255.             }  
    256. return this.getItemAt(this.length-1);  
    257.         }  
    258. /**
    259.          * 在最后位置插入对象,会检查是否存在相同的对象.
    260.          * @param Object
    261.          * @return Boolean true成功 false失败
    262.          */
    263. public function appendItem(o:Object):Boolean{  
    264. //该方法检查每个元素都相同
    265.             var exist:Boolean= this.contains(o);  
    266. if(!exist){  
    267. this.addItem(o);  
    268. //当前游标处理
    269. this.moveCursorTo(o);  
    270. if(this._currentItem){  
    271. return true;  
    272.                 }  
    273.             }  
    274. return false;  
    275.         }  
    276. /**
    277.          * 在当前位置插入一个对象
    278.          * @param Object 
    279.          * @return Boolean
    280.          */
    281. public function insertItem(o:Object):Boolean{  
    282. //该方法检查每个元素都相同
    283.             var exist:Boolean= this.contains(o);  
    284. if(!exist){  
    285. this._cursor.insert(o);  
    286. //当前游标处理
    287. this.moveCursorTo(o);  
    288. if(this._currentItem){  
    289. return true;  
    290.                 }  
    291.             }  
    292. return false;  
    293.         }  
    294. ////////////////////////////////////////////////////////////////////////
    295. ////////////////////////////////////////////////////////////////////////
    296. ////////////////////////////////////////////////////////////////////////
    297. ////////////////////////////////////////////////////////////////////////
    298. /**
    299.          * 删除当前光标指向的对象,并选择下一个对象,如果下一个对象为空,那么选择最后一个
    300.          * @return Object 当前被删除的对象
    301.          * 
    302.          */
    303. public function remove():Object {  
    304.             var o:Object=this._cursor.remove();  
    305. if (!this._currentItem) {  
    306. this._cursor.movePrevious();  
    307.             }  
    308. return o;  
    309.         }  
    310. /**
    311.          * 删除指定的对象
    312.          * @param Object
    313.          * @return Boolean true成功 
    314.          */
    315. public function removeItem(o:Object):Boolean{  
    316. this.moveCursorTo(o);  
    317.             var o:Object = this.remove();  
    318. if(o)return true;  
    319. return false;  
    320.         }  
    321. /**
    322.          * 删除所有数据
    323.          */
    324.         override public function removeAll():void{  
    325. super.removeAll();  
    326. this.source = [];  
    327.         }  
    328. ////////////////////////////////////////////////////////////////////////
    329. ////////////////////////////////////////////////////////////////////////
    330. ////////////////////////////////////////////////////////////////////////
    331. /**
    332.          * 更新当前光标指向的对象
    333.          * @param Object 新的对象
    334.          * @return
    335.          */
    336. public function updateItem(o:Object):void{  
    337.             var keys:Array = MyJSONUtils.fetchKeys(o);  
    338.             var l:int = keys.length;  
    339.             var key:String=null;  
    340. for(var i:int=0;i<l;i++){  
    341.                 key = keys[i];  
    342. if(this._currentItem[key]){  
    343. this._currentItem[key]=o[key];  
    344. this.itemUpdated(this._currentItem);//这个会令ui更新
    345.                 }  
    346.             }  
    347.         }  
    348. ////////////////////////////////////////////////////////////////////////
    349. ////////////////////////////////////////////////////////////////////////
    350. /**
    351.          * 把光标移到指定的对象上,
    352.          * @param Object 目标对象
    353.          * @return Object 当前选择的对象
    354.          */
    355. public function moveCursorTo(o:Object):Object {  
    356. //当前游标处理
    357.             var index:int=this.getItemIndex(o);  
    358. return this.moveCursorByIndex(index);  
    359.         }  
    360. public function moveCursorByIndex(index:int):Object{  
    361. if(index < 0 || index >= this.length)return null;  
    362.             var oldIndex:int = this.getItemIndex(this._currentItem);  
    363.             var offset:int = 0;  
    364. if (oldIndex > index) {  
    365.                 offset = -(oldIndex - index);  
    366.             } else if (oldIndex < index) {  
    367.                 offset = index - oldIndex;  
    368.             }  
    369. this._cursor.seek(this._cursor.bookmark, offset);  
    370. return this._currentItem;  
    371.         }  
    372. /**
    373.          * 光标指向第一个位置,返回第一个位置的值 
    374.          * @return Object 当前光标位置的对象
    375.          */
    376. public function moveFirst():Object{  
    377. //当前游标处理
    378. this._cursor.seek(CursorBookmark.FIRST);  
    379. //当前对象设置值
    380. //在cursor update 事件里面处理了
    381. //返回当前对象
    382. return this._currentItem;  
    383.         }  
    384. /**
    385.          * 光标指向最后一个位置,返回最后一个位置的值 
    386.          * @return Object 当前光标位置的对象
    387.          */
    388. public function moveLast():Object{  
    389. //当前游标处理
    390. this._cursor.seek(CursorBookmark.LAST);  
    391. //当前对象设置值
    392. //在cursor update 事件里面处理了
    393. //返回当前对象
    394. return this._currentItem;  
    395.         }  
    396. /**
    397.          * 光标指向下一个位置,返回光标指向位置的对象
    398.          * @return Object 当前光标位置的对象
    399.          */
    400. public function moveNext():Object {  
    401. if (!this._cursor.afterLast) {  
    402. this._cursor.moveNext();  
    403. //this._currentItem = this._cursor.current;
    404. if (!this._currentItem) {  
    405. this._cursor.movePrevious();  
    406.                 }  
    407.             }  
    408. return this._currentItem;  
    409.         }  
    410. /**
    411.          * 光标指向上一个位置,返回光标指向位置的对象
    412.          * @return Object 当前光标位置的对象
    413.          */
    414. public function movePrevious():Object {  
    415. if (!this._cursor.beforeFirst) {  
    416. this._cursor.movePrevious();  
    417. if (!this._currentItem) {  
    418. this._cursor.moveNext();  
    419.                 }  
    420.             }  
    421. return this._currentItem;  
    422.         }  
    423. ////////////////////////////////////////////////////////////////////////
    424. ////////////////////////////////////////////////////////////////////////
    425. /**
    426.          * 把值转成字符串
    427.          * @return String 
    428.          */
    429.         override public function toString():String{  
    430.             var s:String = "";  
    431.             var l:int=this.length;  
    432. for(var i:int=0;i<l;i++){  
    433.                 s+=MyJSONUtils.encode(this.getItemAt(i));  
    434.             }  
    435. return s;  
    436.         }  
    437.     }//end class
    438. }//end package
  • 相关阅读:
    C#中Split用法
    ASP.NET Get和Post两种提交的区别:
    BAT常用命令
    SQL语句:在两个数据库间复制表结构和数据数据库
    C#中Array与ArrayList用法及转换
    找出输入区间内的回文质数
    (转)加藤嘉一:中国大学生,你没资格抱怨政府
    最长公共子序列(LCS)
    shell(希尔)排序
    关于Ubuntu中google chrome浏览器字体的设置
  • 原文地址:https://www.cnblogs.com/pyrmkj/p/2583886.html
Copyright © 2011-2022 走看看