0

如果我有一些 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>

我想将它绑定到一个火花多选列表,我怎样才能使项目选择值绑定到 xml 元素的包含属性?此外,如果它被取消选择,它如何自动将此值从 true 切换为 false?

感谢您的任何提示!

4

1 回答 1

2

将 xml 作为 XMLListCollection 提供给列表。然后单击处理 selectedItems。请阅读下面给出的代码片段,它可能会有所帮助

<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml”
layout=”absolute”
creationComplete=”init()”&gt;
<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”&gt;</mx:List>
</mx:Application>
于 2012-06-01T11:14:48.783 回答