3 Replies Latest reply on Apr 19, 2011 7:42 AM by Flex harUI

    arraycollection return index -1 after refreshed in datagrid

    davy zhang

      when I called data.refresh();  the arraycollection.getItemIndex(obj1) will return -1 

       

      is there anyway to get it work correctly or work around ?

       

      <?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"  preinitialize="application1_preinitializeHandler(event)"

        xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" xmlns:local="*">

      <fx:Script>

      <![CDATA[

      import mx.collections.ArrayCollection;

      import mx.collections.Sort;

      import mx.events.FlexEvent;

       

       

      private var data:ArrayCollection;

      private var obj1:Object;

      protected function application1_preinitializeHandler(event:FlexEvent):void

      {

      obj1  = {"name":"1"}

      data = new ArrayCollection();

      data.addItem(obj1);

      data.addItem({"name":"2"});

       

      trace(data.getItemIndex(obj1));//0

       

       

      var sort:Sort = new Sort();

      sort.compareFunction = nameSort;

      data.sort = sort;

      data.filterFunction=null;

       

      data.refresh();

      trace(data.getItemIndex(obj1))//-1

          }

       

      private function aa():void{

      }

       

      private function nameSort(m1:Object, m2:Object,arr:Array=null):int {

      return -1;

      }

       

      ]]>

      </fx:Script>

      <fx:Declarations>

       

      </fx:Declarations>

       

       

      </s:Application>