views:

44

answers:

1

I am acquiring the contents of a table to fill a dropdown box in a Flex 3 application:

<mx:ComboBox dataSource="{myList}" />

The list is populated by the contents of a database table of persons:

Public, John Q
Doe, Jane
...

The combo box, however, also needs to have some other meta-entries in it that do not come from the database:

ALL
ALL MEN
ALL WOMEN
Public, John Q
Doe, Jane
...

What is the best way to do this?

+1  A: 

Override the setter for "mylist" and insert your values into the array.

public function set myList(value:Array):void {
  this._myList = ["ALL MEN", "ALL_WOMEN"].concat(value);
  this.dispatch(new FlexEvent(FlexEvent.DATA_CHANGE));
}
Glenn
This seems a bit... clunky. Also, when I need the values of myList for programmatic access in other situations this won't work.
Chris R
Sure it will. You write a getter that returns _mylist and it contains the two new values. You can try to make it as elegant as you like, but it will be a variation on this. Maybe you want to override the combobox and insert these extra ones when someone assigns the dataprovider.
Glenn
I did this in a slightly different place; the source field for my array collection performs this concatenation, since that's where the knowledge of the special handling lives.
Chris R