<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import mx.utils.UIDUtil;
import mx.collections.ArrayCollection;
import mx.utils.ObjectUtil;
[Bindable]
public var dataArr:Array = [{label:"Red",data:"#FF0000"},
{label:"Green",data:"#00FF00"},
{label:"Blue",data:"#0000FF"}
];
[Bindable]
public var problemArr:Array = new Array();
private function addFromTopDG():void {
problemArr.push(fromDG.selectedItem);
//problemArr.push(ObjectUtil.copy(fromDG.selectedItem));
toDG.dataProvider = problemArr;
}
private function addFromTopDG2():void {
var obj:Object = ObjectUtil.copy(fromDG.selectedItem);
obj.mx_internal_uid = UIDUtil.createUID();
//这里千万不要直接fromDG.selectedItem.mx_internal_uid = UIDUtil.createUID();
//因为上面说过这样引用关系还存在。
(toDG.dataProvider as ArrayCollection).addItem(obj);
obj = null;//这个就靠自己的CODE 风格啦,不要也没关系
}
]]>
</mx:Script>
<mx:DataGrid id="fromDG" width="600" height="200" dataProvider="{dataArr}">
<mx:columns>
<mx:Array>
<mx:DataGridColumn width="300" datafield="mx_internal_uid"/>
<mx:DataGridColumn datafield="label"/>
<mx:DataGridColumn datafield="data"/>
</mx:Array>
</mx:columns>
</mx:DataGrid>
<mx:Button label="Add from Top_DG" click="addFromTopDG()"/>
<mx:DataGrid id="toDG" width="600" height="200" dataProvider="{problemArr}">
<mx:columns>
<mx:Array>
<mx:DataGridColumn width="300" datafield="mx_internal_uid"/>
<mx:DataGridColumn datafield="label"/>
<mx:DataGridColumn datafield="data"/>
</mx:Array>
</mx:columns>
</mx:DataGrid>
</mx:Application>
来源:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。