6 Replies Latest reply on Feb 19, 2010 5:02 AM by Kirill88

    get item by UID


      How can I get item from ArrayCollection by UID?

      Can set selectedUID in ListBase control or set selectedItem by UID.



        • 1. Re: get item by UID
          archemedia Level 4

          Why use UID?

          What do you want to achieve?



          • 2. Re: get item by UID
            Kirill88 Level 1

            I have two database tables with dependencies. First table already loaded from db to client. I want to link fields dependencies between loaded items, when data from second table will be loaded in next time. I have to translate UID to object for this case.

            • 3. Re: get item by UID
              archemedia Level 4

              When the two tables are loaded, you can call a function to merge them, like this:


              <?xml version="1.0" encoding="utf-8"?>
              <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
                          import mx.collections.ArrayCollection;
                          private var dp:ArrayCollection;
                          private function init():void
                              var t1:Array = [{id: 1, val: "France"}, {id: 2, val: "England"}];
                              var t2:Array = [{id: 1, val: "Paris", fk: 1},
                                              {id: 2, val: "London", fk: 2},
                                              {id: 3, val: "Liverpool", fk: 2},
                                              {id: 4, val: "Bordeaux", fk: 1},
                                              {id: 5, val: "Manchester", fk: 2},
                                              {id: 6, val: "Nantes", fk: 1}];
                              for each (var country:Object in t1)
                                  var cities:ArrayCollection = new ArrayCollection();
                                  for each (var city:Object in t2)
                                      if (city.fk == country.id)
                                  country.children = cities;
                              dp = new ArrayCollection(t1);
                  <mx:Tree dataProvider="{dp}" labelField="val" width="400" height="600"/>



              1 person found this helpful
              • 4. Re: get item by UID
                Kirill88 Level 1

                Thanks for reply.

                I use cursor.findFirst() for searching related item in ArrayCollection. What can you say about performance? Is for each() may be faster? And what can you say about performance when size of incoming arrayCollection will be more big???

                • 5. Re: get item by UID
                  archemedia Level 4

                  In my experience, array function are very fast. I use the filter function of the Array class a lot on array with over 8000 items. It's almost instantanious!

                  Very powerful!



                  • 6. Re: get item by UID
                    Kirill88 Level 1

                    Thanks, Dany. I wrote small component for control dependences between ListCollectionView's.