2012-01-20 18 views
0

我需要獲取節點打開的advanceddatagrid中每行的數據。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 

任何建議將高度讚賞。謝謝

回答

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對象的源代碼,並將正確的值放入一個新的具有主題和合格的值對象中或者設置失敗。然後你可以存儲這些值,同時也注意到我假設傳球失敗總是以原始數據結構的形式組織起來,在每個主題中你將有兩個數組,第一個是傳遞,然後是失敗。