actionscript 3 - Bidirectional binding for flex ComboBox? -


i have collection want bind data input combobox:

private static var logos:arraycollection = new arraycollection([  {index:0, label=logo1},   {index:1, label=logo2} ]);  <s:combobox selecteditem="@{model.labelindex}" labelfield="@label" dataprovider="{logos}" /> 

now, when selecting item, binding should send associated index property of objext model , update labelindex. of course not work above, because labelindex of different datatype arraycollection.

[bindable] private var model:mymodel;  [bindable] class mymodel {    public var:number labelindex; } 

question: how can map array element model , vice versa?

what looking require scripting, binding isn't smart enough figure out how handle on own.

you can use bindingutils class define bindings, , use chain argument of bindproperty method modify how values being looked up.

http://help.adobe.com/en_us/flashplatform/reference/actionscript/3/mx/binding/utils/bindingutils.html

for combo.selecteditem model.labelindex binding, can specify chain array, elements define path value:

bindingutils.bindproperty(model, 'labelindex', combo, ['selecteditem', 'index']); 

this bind selecteditem property, , pass value of items index property.

the other way around little more tricky , require using getter function grabs object datasource, based on labelindex value:

bindingutils.bindproperty(combo, 'selecteditem', model, {     name: 'labelindex',     getter: function(host:mymodel):object     {         return logos.source.filter(function(item:object, index:int, array:array):boolean         {             return item.index === host.labelindex;         })[0];     } }); 

this bind labelindex property, , getter function invoked when property changes. function filter datasource based on models changed labelindex property value, , return source object matching index property value, set combobox selecteditem property.

your combobox definition of course need id in order targetable via script

<s:combobox id="combo" dataprovider="{logos}" /> 

note there's no need forthe @ in labelfield property, used xml datasources need target attribute. however, don't need specify @ all, since label default value of labelfield property.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -