2012-10-10 19 views
2

我有一個對象的源對象的ArrayCollection。我的目標看起來大致是這樣的:Flex:過濾HierarchicalData子行

ObjectName (String) 
SubCollection (ArrayCollection) 

我使用HierarchicalData在移動AdvancedDataGrid的分組格式來顯示數據。

我可以使用filterFunction過濾ArrayCollection中的數據。我現在要做的也是過濾SubCollection中的記錄,以便只有與過濾器匹配的項目纔會顯示在AdvancedDataGrid中。

誰能告訴我如何在HierarchicalData中篩選子行?

+0

遞歸環路和的filterFunction適用於每個子集合。 – RIAstar

+0

@RIAstar我試過這樣做。在調試過程中,我可以看到'SubCollection'在過濾後有正確數量的項目,但'AdvancedDataGrid'仍然顯示完整的項目列表。有什麼建議麼? –

+0

收集完成後,視圖中的聲音未被刷新。 「AdvancedDataGrid」有時可以是皇家PITA(很好,大部分時間都是)。 – RIAstar

回答

2

This answer不是你的問題的直接答案,但它應該有助於一些背景。基本上我和你處於同樣的位置,我需要根據我所擁有的父節點類型來顯示特定的數據集。

在這種情況下,從覆蓋開始到HierarchicalData.getChildren(node:Object):Object這將允許您訪問篩選一級子級,並且還會爲您提供調用任何第n級子子級篩選方法的能力。

然後,您使用擴展類作爲ADG的來源。

的僞代碼示例:通過它

Class MyCollection extends HierarchicalData 

override public function getChildren(node:Object):Object 
{ 
    if (node is a TopLevelObject) 
     (node.children as ArrayCollection).filterFunction = filterSub; 
     node.children.refresh(); 
    else if (node is a SubCollectionObject) 
     (node.children as ArrayCollection).filterFunction = filterGrandChildren; 
     node.children.refresh(); 

    // - OR - 
     //a more complex process of allowing the sub-node to determine it's filter 
     return node.filterSubCollectionGrandChildren(); 


    return node; 
} 
+0

邁克,你是男人!經過許多小時的挫折之後,你的回答讓我朝着正確的方向前進。謝謝。 –

+0

不客氣;) –

+0

還有一個問題,如果我可以。你的回答幫助我得到了我想要的過濾結果,但現在我遇到了使用AdvancedDataGrid的'expandAll()'和'collapseAll()'方法的問題。你之前遇到過這種情況嗎? –