Reputation: 3415
If I have some xml, like a list of languages that looks like:
<otherLanguages>
<language code="fr" localName="Français" englishName="French" lastModified="5/30/2012 2:42:18 PM" whenCreated="5/30/2012 2:42:18 PM" baseId="2809988" included="false"/>
<language baseId="2809989" lastModified="5/30/2012 2:44:57 PM" whenCreated="5/30/2012 2:44:57 PM" englishName="Spanish" localName="Español" code="es" included="false"/>
</otherLanguages>
And I want to bind this to a spark multiselect list, how can I make the items selected value bind to the included property of the xml element? Also, how can it auto toggle this value from true to false if it becomes de-selected?
Thanks for any tips!
Upvotes: 0
Views: 318
Reputation: 1477
Feed xml as XMLListCollection to the list. Then on click handle the selectedItems. Please read the code snippet given below, it might be helpful
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml”
layout=”absolute”
creationComplete=”init()”>
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
var selectedArr : ArrayCollection;
public function init() : void
{
selectedArr = new ArrayCollection();
list.selectedItems = selectedArr.toArray();
}
public function selected(event:Event) : void
{
var selected : String = arr.getItemAt(event.currentTarget.selectedIndex).toString();
if(!selectedArr.contains(selected))
{
selectedArr.addItem(selected);
}
else
{
selectedArr.removeItemAt(selectedArr.getItemIndex(selected));
}
list.selectedItems = selectedArr.toArray();
}
]]>
</mx:Script>
<mx:List id=”list”
x=”251?
y=”77?
dataProvider=”{arr}”
width=”356?
click=”selected(event)”
allowMultipleSelection=”true”></mx:List>
</mx:Application>
Upvotes: 2