flex中DataGrid里使用itemRenderer后数据无法绑定到数据源的问题

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="initApp()" layout="vertical" fontSize="12" backgroundColor="white">

<mx:Script>
<![CDATA[

import mx.collections.ArrayCollection;

[Bindable]
private var AC1:ArrayCollection;

private function initApp():void{
AC1=new ArrayCollection([{name:"开会",type:"紧急",steps:"0"},
{name:"结算",type:"一般",steps:"0"},
{name:"放假",type:"一般",steps:"0"}]);

}

protected function fun_AddImage(event:MouseEvent):void
{
trace(AC1);

for(var i:int=0; i<AC1.length; i++) {
trace(AC1[i].steps);

}
}

]]>
</mx:Script>

<mx:DataGrid rowCount="4" dataProvider="{AC1}" id="dg" >
<mx:columns>
<mx:DataGridColumn headerText="name" dataField="name"/>
<mx:DataGridColumn headerText="type" dataField="type"/>
<mx:DataGridColumn headerText="email">
<mx:itemRenderer>
<mx:Component>
<mx:TextInput text="{data.steps}"/>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>

<mx:Button x="326" y="513" label="测试数据" click="fun_AddImage(event)"/>

</mx:Application>

调试提示:
warning: unable to bind to property 'steps' on class 'Object' (class is not an IEventDispatcher)

现在需要的效果是在DG的输入框里修改了文字后,数组ac1的steps字段也会更着修改
点测试后出现的数字是在DG中输入的数字,现在的问题应该是自定义的列无法和数据源ac1中的steps绑定的问题。



/*如果数据只是文本的,下面的代码就可以完成你要的功能
* 注意 editable="true"
*如果是复杂的数据类型,需要在列中定义 itemEditor="{new ClassFactory(XXXX)}"
*<< 狗狗熊 奉上 >>
*/

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="initApp()" layout="vertical" fontSize="12" backgroundColor="white">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
private var AC1:ArrayCollection;
private function initApp():void{
AC1=new ArrayCollection([{name:"开会",type:"紧急",steps:"0"},
{name:"结算",type:"一般",steps:"0"},
{name:"放假",type:"一般",steps:"0"}]);
}

protected function fun_AddImage(event:MouseEvent):void
{
trace(AC1);

for(var i:int=0; i<AC1.length; i++) {
trace(AC1[i].steps);

}
}

]]>
</mx:Script>
<mx:DataGrid rowCount="4" dataProvider="{AC1}" id="dg" editable="true" >
<mx:columns>
<mx:DataGridColumn headerText="name" dataField="name" editable="false"/>
<mx:DataGridColumn headerText="type" dataField="type" editable="false"/>
<mx:DataGridColumn headerText="email" dataField="steps" />
</mx:columns>
</mx:DataGrid>
<mx:Button x="326" y="513" label="测试数据" click="fun_AddImage(event)"/>
</mx:Application>



AC1=new ArrayCollection([{name:"开会",type:"紧急",steps:"0"},
{name:"结算",type:"一般",steps:"0"},
{name:"放假",type:"一般",steps:"0"}]);
}
改成:
var array1:Array = [{name:"开会",type:"紧急",steps:"0"},
{name:"结算",type:"一般",steps:"0"},
{name:"放假",type:"一般",steps:"0"}];
var array2:Array = new Array();
for(var i:int = 0;i<array1.length;i++){
array2.push(new ObjectProxy(array1[i]));
}
AC1 = new ArrayCollection(array2);

原因:ObjectProxy实现了IEventDispatcher接口
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值