apache-flex - Flex 警告 : Unable to bind to property 'foo' on class 'Object' (class is not an IEventDispatcher)

标签 apache-flex actionscript-3 binding flex3 mxml

我有一个对象,其中包含十几个要绑定(bind)到表单元素的字段,以便我可以使用该对象将数据发送回服务器以进行保存。

我的容器对象的定义:

private static const emptyLink:Object = {
    id: -1, title:'',
    trigger1:'',trigger2:'',trigger3:'',trigger4:'',trigger5:'',
    linkTitle:'', linkBody:'',
    answer1:'',answer2:'',answer3:'',answer4:'',answer5:''
};

[Bindable] public var currentLink:Object = emptyLink;
currentLink在运行时分配给 ArrayCollection 中的特定索引,我只是使用 emptyLink主要用于初始化目的的对象。
<mx:Panel id="triggerPanel" title="Trigger" width="33%">
    <mx:VBox id="tpBoxes" width="100%" paddingBottom="5" paddingLeft="5" paddingRight="5" paddingTop="5">
        <mx:TextInput id="trigger1" width="100%" textAlign="left" text="{currentLink.trigger1}" />
        <mx:TextInput id="trigger2" width="100%" textAlign="left" text="{currentLink.trigger2}" />
        <mx:TextInput id="trigger3" width="100%" textAlign="left" text="{currentLink.trigger3}" />
        <mx:TextInput id="trigger4" width="100%" textAlign="left" text="{currentLink.trigger4}" />
        <mx:TextInput id="trigger5" width="100%" textAlign="left" text="{currentLink.trigger5}" />
    </mx:VBox>
</mx:Panel>

当然,这编译并显示得很好,但是每个实例都有运行时警告:

warning: unable to bind to property 'trigger1' on class 'Object' (class is not an IEventDispatcher) warning: unable to bind to property 'trigger2' on class 'Object' (class is not an IEventDispatcher) warning: unable to bind to property 'trigger3' on class 'Object' (class is not an IEventDispatcher) warning: unable to bind to property 'trigger4' on class 'Object' (class is not an IEventDispatcher) warning: unable to bind to property 'trigger5' on class 'Object' (class is not an IEventDispatcher)



currentLink TextInput 时对象未更新字段被更改。

显而易见的答案是我的对象需要是实现 IEventDispatcher 的类的实例。 .该答案没有告诉我的是实现该接口(interface)的细节(需要什么?什么不是?),以及是否有更简单的方法来做到这一点——比如一个内置类,它很乐意接受我的自定义属性并允许对于绑定(bind),我不必担心实现接口(interface)的细节。

这样的类存在吗?如果不是,那么完成这项任务的最低限度和/或公认标准是什么?

最佳答案

您需要使用 ObjectProxy (正如 Chetan 提到的) - 但您还需要使用 valueCommit 将您在输入中输入的文本返回到您的对象中:

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    <mx:Script>
        <![CDATA[
            import mx.utils.ObjectProxy;
              private static const emptyLink:Object = {
    id: -1, title:'',
    trigger1:'',trigger2:'',trigger3:'',trigger4:'',trigger5:'',
    linkTitle:'', linkBody:'',
    answer1:'',answer2:'',answer3:'',answer4:'',answer5:''
};

[Bindable] public var currentLink:ObjectProxy = new ObjectProxy(emptyLink);


private function handleClick():void
{
    trace(currentLink.trigger1);
}
]]>
</mx:Script>

<mx:Panel id="triggerPanel" title="Trigger" width="33%">
        <mx:VBox id="tpBoxes" width="100%" paddingBottom="5" paddingLeft="5" paddingRight="5" paddingTop="5">
                <mx:TextInput  id="trigger1" width="100%" textAlign="left" text="{currentLink.trigger1}" valueCommit="{currentLink.trigger1 = trigger1.text;}"/>

                <mx:Button label="Click" click="handleClick()"/>
        </mx:VBox>
</mx:Panel>        

</mx:WindowedApplication>

关于apache-flex - Flex 警告 : Unable to bind to property 'foo' on class 'Object' (class is not an IEventDispatcher),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/928081/

相关文章:

apache-flex - 柔性 : Call function from included component

c# - Windows Phone 8.1 应用程序上的双向绑定(bind),使用 MVVM

swift - 如何在 SwiftUI 中将测量与 UI 绑定(bind)?

apache-flex - Flex - 在 MXML 代码中使用百分比绑定(bind)宽度属性

apache-flex - 在 groovy/grails 中使用元编程拦截服务方法调用

java - BlazeDS、Flex 和 Java - 我能否将 RemoteObject 视为 Java 类的实例?

flash - 如何在 Action 中实现视线限制?

android - 安卓模拟器上的八哥

ios - 定义使用 iOS 相机 Adob​​e Air 拍摄的图像

c# - 为什么两个多重绑定(bind)中只有一个有效?