我在许多项目中使用了datagrid,使用以下“常用数据结构”填充网格,并带来标准o / p,如下图所示。 但是现在对于一个赋值,我想使用下面提到的“复杂数据结构”(嵌套数组)来获得相同的网格结果。我有一些想法是在将数据推送到网格之前处理数据,但问题是我需要执行一些更新,通过网格渲染器编辑删除操作,同样也应该反映到源集合中。请让我知道有没有办法可以使用“复杂结构”并使用任何flex in build属性带来预期的o / p。提前致谢。
通常的数据结构
steps = [a,b,c];
a = {x:100,y:y1,z:z1};
b = {x:200,y:y2,z:z2};
c = {x:300,y:y3,z:z3};
复杂的数据结构
[] is an Array collection not Array type.
a = [100,y1,z1];
b = [200,y2,z2];
c = [300,y3,z3];
steps = [[a,some objects],[b,some objects],[c,some objects]];
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
private var a:ArrayCollection = new ArrayCollection(['x1','y1','z1']);
private var b:ArrayCollection = new ArrayCollection(['x2','y2','z2']);
private var c:ArrayCollection = new ArrayCollection(['x3','y3','z3']);
[Bindable]
private var stepsObjs:ArrayCollection = new ArrayCollection([{ items: a},{ items: b},{ items: c}]);
]]>
</mx:Script>
<mx:DataGrid dataProvider="{stepsObjs}" >
<mx:columns>
<mx:DataGridColumn dataField="items.0" headerText="x" />
<mx:DataGridColumn dataField="items.1" headerText="y" />
<mx:DataGridColumn dataField="items.2" headerText="z" />
</mx:columns>
</mx:DataGrid>
</mx:Application>
答案 0 :(得分:3)
编辑更换代码以解决新问题。
这个对我有用:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
private var a:ArrayCollection = new ArrayCollection([100,'y1','z1']);
private var b:ArrayCollection = new ArrayCollection([200,'y2','z2']);
private var c:ArrayCollection = new ArrayCollection([300,'y3','z3']);
private var stepsObjs:ArrayCollection = new ArrayCollection([{ items: a},{ items: b},{ items: c}]);
private var stepsColl:ArrayCollection = new ArrayCollection([[a],[b],[c]]);
]]>
</fx:Script>
<s:layout>
<s:VerticalLayout />
</s:layout>
<mx:DataGrid dataProvider="{stepsObjs}" >
<mx:columns>
<mx:DataGridColumn dataField="items.0" headerText="x" />
<mx:DataGridColumn dataField="items.1" headerText="y" />
<mx:DataGridColumn dataField="items.2" headerText="z" />
</mx:columns>
</mx:DataGrid>
<mx:DataGrid dataProvider="{stepsColl}" >
<mx:columns>
<mx:DataGridColumn dataField="0.0" headerText="x" />
<mx:DataGridColumn dataField="0.1" headerText="y" />
<mx:DataGridColumn dataField="0.2" headerText="z" />
</mx:columns>
</mx:DataGrid>
</s:Application>
答案 1 :(得分:1)
itemRenderers应该发送一个描述应该发生什么的事件,然后应该将其处理得更高。
像这样:
//inside item renderer
dispatchEvent(new ItemEvent(ItemEvent.DELETE_ITEM, true, item));//where true tells the event to bubble (you'll need to create this event)
//somewhere above the DataGrid
dataGrid.addEventListener(ItemEvent.DELETE_ITEM, deleteItemFromSource);
protected function deleteItemFromSource(e:ItemEvent):void {
var lcv:ListCollectionView = (dataGrid.dataProvider as ListCollectionView);
lcv.removeItemAt(lcv.getItemIndex(e.item));
}
请注意,如果您希望数据网格在更改时自动更新,那么您应该使用某种ListCollectionView,不数组。
HTH;
艾米