AdvancedDatagrid迭代Open Leaf / Tree的每一行

时间:2012-01-20 03:20:41

标签: flex actionscript advanceddatagrid

我需要获取节点打开的高级数据网格中每一行的数据。

例如,我的ADG看起来像这样:

+ Science
- Math
  - Passed
     John Doe    |  A+  |  Section C
     Amy Rourke  |  B-  |  Section B
  - Failed
     Jane Doe    |  F   |  Section D
     Mike Cones  |  F   |  Section D
- English
  + Passed
  + Failed
- History
  + Passed
  - Failed
     Lori Pea    |   F  |  Section C

我尝试使用以下代码来获取开放节点:

var o:Object = new Object();
o = IHierarchicalCollectionView(myADG.dataProvider).openNodes;

但是执行以下代码来检查对象:

Alert.show(ObjectUtil.toString(o), 'object inpsection');

给我:

(Object)#0
  Math (2)
    children = (mx.collections::ArrayCollection)#2
      filterFunction = (null)
      length = 2
      list = (mx.collections::ArrayList)#3
        length = 2
        source = (Array)#4
          [0] (Object)#5
            children = (mx.collections::ArrayCollection)#6
              filterFunction = (null)
              length = 2
              list = (mx.collections::ArrayList)#7
                length = 2
                source = (Array)#8
                  [0] <Table>
    <Name>John Doe</Name>
    <Grade>A+</Grade>
    <Section>Section C</Section>
</Table>
                  [1] <Table> 
    <Name>Amy Rourke</Name>
    <Grade>B-</Grade>
    <Section>Section B</Section>
....
...
..

基本上,我只需要创建一个对象或数组或xmllist来给我:

Math    |   Passed  |   John Doe    |   A+  |   Section C
Math    |   Passed  |   Amy Rourke  |   B-  |   Section B
Math    |   Failed  |   Jane Doe    |   F   |   Section D
Math    |   Failed  |   Mike Cones  |   F   |   Section D
History |   Failed  |   Lori Pea    |   F   |   Section C

任何建议都将受到高度赞赏。感谢

1 个答案:

答案 0 :(得分:0)

您应该能够遍历openNodes对象的属性,并且每个属性都会抓取集合并将值连接到新数组,然后在必要时将其用作另一种类型集合的源。像这样:

var newArray:Array = [];
for(var property:String in o)
{
    newArray = newArray.concat(o[property][0].source); //Passed, property is subject as in Math
    newArray = newArray.concat(o[property][1].source); //Failed property is subject as in Math
}

唯一真正的问题是你试图保持数学并在对象中传递或失败,否则上述应该有效。为了使这个其他部分工作,我认为你需要将上面的每个语句分解为它自己的循环,它遍历openNodes对象的源并将正确的值放入你组成的具有主题和传递的新值对象中或者设置失败。然后你也可以存储这些值,同时注意我假设传递失败总是以这种方式组织在原始数据结构中,在每个主题中你将有两个数组,第一个将通过然后失败。