【问题标题】:Flex - databinding from a Tree to a RepeaterFlex - 从树到中继器的数据绑定
【发布时间】:2008-12-04 21:31:13
【问题描述】:

我正在尝试在 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 被传递到(自定义)组件中。 该组件(不确定这是否是最好的方法,但仍然......) - 有几个中继器控件 - 一个绑定到 XMLList 用于广播问题,另一个绑定到 XMLList 的检查盒子问题。 每个转发器循环选项的数量,放置一个 TextInput(编辑选项文本)和一个单选框或复选框(取决于问题类型)

所以 - 我所追求的是当为一个选项编辑文本时,该 TextInput 中的 XML 绑定到作为树的 dataProvider 的 XML。因此,例如,如果“这是选项 1”更改为“这是选项 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。我知道我可以使树本身可编辑,但这并不是一个真正的选择。

因此,任何指针或想法将不胜感激!

【问题讨论】:

    标签: xml apache-flex data-binding tree repeater


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 2016-08-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-10-25
        • 2011-04-11
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多