1 Star2 Stars3 Stars4 Stars5 Stars
Loading ... Loading ...

Data Binding an Array in Flex?

Can you do it?  No you can’t.

Not directly anyway – Arrays aren’t something that data binding works with in Flex.  ArrayCollection however, is something you can work with.  To use an Array as a bindable object, you can wrap it in an ArrayCollection.  It’s similar, but not the same as an Array – you can’t push, pull, pop or shift things anymore – you have to work with other methods like addItem or removeItem.

I would’ve liked to find that all of those classic array methods still worked, but what can you do?

4 Comments »

  1. The property ArrayCollection.source is the very array that resides inside an AC , thus it allows access to Array methods ( mycollectionAC.source.indexOf(…) ).
    Just experiment with that to see if it’s of any help to you.
    It’s feasible and can maybe be handy but I would advise you to test the limits of this way of doing so, especially if you plan to modify the ArrayCollection items.

    Or then you can replace your source array property with a modified one in your AC. It’s for you to see.

    Comment by DavidD — 2 February 2009 #

  2. Oh, that makes a lot of sense! – I can see why they’d want to do it that way. – Cheers!

    Comment by James — 2 February 2009 #

  3. Don’t forget that things you do to the array might not show up (since it’s not bindable) and you might need to fire off an event like refresh() on the ArrayCollection if you using the .source property.

    Comment by Bruce — 2 February 2009 #

  4. oh yeah, if you’re using a DataService ArrayCollection you might find that the list property is populated instead of the .source, so be careful of that as well.

    Comment by Bruce — 2 February 2009 #

Leave a comment

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Note: This post is over a year old. You may want to check later in this blog to see if there is new information relevant to your comment.