views:

259

answers:

2

I have following code.

<s:DropDownList dataProvider={_dataProvider}/>
<fx:Script>
   private var _dataProvider:ArrayCollection = new ArrayCollection([{label:"one", data:1}, {label:"two", data:2}]);
</fx:Script>

I want to bind the data property of the selectedItem in the DropDownList. Is there a way to do this?

+1  A: 

I'm pretty sure the answer is no, but just to be clear; I'm confused.

If your dataProvider contains objects like this:

{label:"one", data:1}

First off, this syntax will create a generic object with no customization. If none of the properties on that object are explicitly defined, none of them can implement the Bindable metadata tag, and therefore when used as the source for data binding, the target will never update.

Second off, even if you created your own non-generic object with properties being bindable, binding doesn't usually go multiple levels deep into an object's properties of an array.

The selectedItem will point to an object like are in your _dataProvider, or possibly null, based on user interaction with the dropDownList. Binding the selectedItem to a property inside the item doesn't make sense; because you'd be comparing an literal to an object and nothing would ever be selected.

I'm unclear, without looking, what happens in the DropDownList when you try to set selectedItem to an item not in your dataProvider. I imagine it resets the selection, though.

If you can expand on what exactly you're trying to accomplish we may be able to help more.

www.Flextras.com
Ok I should've been clearer. I wanted the data to bind to a property in the presentation model. but I was just being dumb.. I should've had the dataProvider in the presentation model to begin with.. Now i have properties set in the presentation model which handles extracting data.
lordofthefobs
So, you're set then? Or not?
www.Flextras.com
+1  A: 
<s:DropDownList id="ddl" dataProvider="{_dataProvider}"/>
<s:Label text="{ddl.selectedItem.data.toString()}"/>
Amarghosh