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

你可能感兴趣的:(itemRenderer)