【问题标题】:2 way data binding with flex 4 list and multiselect使用 flex 4 列表和多选进行 2 路数据绑定
【发布时间】:2012-05-31 00:08:58
【问题描述】:

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

感谢任何提示!

【问题讨论】:

  • 最简单的方法是创建一个双向可绑定数组集合

标签: xml actionscript-3 flex4


【解决方案1】:

将 xml 作为 XMLListCollection 提供给列表。然后单击处理选定的项目。请阅读下面给出的代码 sn-p,它可能会有所帮助

<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>

【讨论】:

  • 我会将其标记为正确,因为它看起来会起作用,对于我的情况,我最终选择了一个数据组和复选框,效果很好。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-09-05
  • 1970-01-01
  • 2021-08-18
  • 1970-01-01
  • 1970-01-01
  • 2018-05-18
  • 1970-01-01
相关资源
最近更新 更多