简体   繁体   English

与flex 4 list和multiselect的2路数据绑定

[英]2 way data binding with flex 4 list and multiselect

If I have some xml, like a list of languages that looks like: 如果我有一些xml,就像一个看起来像这样的语言列表:

<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? 我想将它绑定到一个spark多选列表,如何使选中的项绑定到xml元素的包含属性? Also, how can it auto toggle this value from true to false if it becomes de-selected? 此外,如果取消选择此值,它如何自动将此值从true切换为false?

Thanks for any tips! 谢谢你的任何提示!

Feed xml as XMLListCollection to the list. 将XML作为XMLListCollection提供给列表。 Then on click handle the selectedItems. 然后单击处理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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM