Flex - 从树到中继器的数据绑定

时间:2008-12-04 21:31:13

标签: xml flex data-binding tree repeater

我正在尝试在flash中创建一个XML问题编辑器。 基本上我将XML加载到Tree组件中 - XML就像这样:

<questions>
<question id="1" type="radio" text="This is question 1" isBranch="true">
  <option id="1.1" correct="false" text="This is option 1" />
  <option id="1.2" correct="false" text="This is option 2" />
  <option id="1.1" correct="false" text="This is option 1" />
  <option id="1.2" correct="false" text="This is option 2" />
  <option id="1.3" correct="true" text="This is option 3" />
  <option id="1.4" correct="false" text="This is option 4" />
</question>
<question id="2" type="check" text="This is question 2" isBranch="true">
  <option id="2.1" correct="true" text="This is option 1" />
  <option id="2.2" correct="false" text="This is option 2" />
  <option id="2.3" correct="true" text="This is option 3" />
</question>
</questions>

所以进入树。在变化时,我得到所选问题(item..option)的选项列表 - 并且该XMLList被传递到(自定义)组件中。 那个组件(不确定这是否是最好的方法,但仍然......) - 有几个Repeater控件 - 一个绑定到XMLList的无线电问题,另一个绑定到一个检查的XMLList盒子问题。 每个转发器循环选项的数量,将TextInput放入(以编辑选项文本)和收音机或复选框(取决于问题类型)

所以 - 我所追求的是当为一个选项编辑文本时,该TextInput中的XML被绑定到XML,该XML是树的dataProvider。因此,例如,如果“This is option 1”更改为“This is option Foo” - 树将更新。

到目前为止,我的中继器(例如无线电)就像这样

<mx:Repeater id="repeaterRadio" dataProvider="{optionsListRadio}">      
  <mx:TextInput width="359" id="radioText"
     editable="true" enabled="true" text="{repeaterRadio.currentItem.@text}"/>
  <mx:RadioButton id="radioArray"
    data="{repeaterRadio.currentItem.@id}"
    selected="{repeaterRadio.currentItem.@correct=='true'}"/>
</mx:Repeater>

没有约束力 - 我到这里的所有警告都是:

warning: unable to bind to property 'text' on class 'XML' (class is not an IEventDispatcher)

我有点理解为什么会出现这种情况,但我不知道如何绑定用户可以编辑回源xml的数据。我知道我可以让树本身可编辑,但这不是一个真正的选择。

所以任何指针或想法都会非常感激!

2 个答案:

答案 0 :(得分:0)

我认为有两个类可以帮助将XML转换为可绑定对象,然后在用户完成后重新转换回XML,mx.rpc.xml.SimpleXMLDecodermx.rpc.xml.SimpleXMLEncoder

答案 1 :(得分:0)

只需将repeaterRadio.currentItem.@text替换为XML(repeaterRadio.currentItem).@text