【问题标题】:Flex: Filter HierarchicalData child rowsFlex:过滤 HierarchicalData 子行
【发布时间】:2012-10-10 18:15:47
【问题描述】:

我有一个ArrayCollection 对象用作HierarchicalData 对象的源。我的对象大致是这样的:

ObjectName (String)
SubCollection (ArrayCollection)

我在 AdvancedDataGrid 中使用HierarchicalData 以分组格式显示数据。

我可以使用filterFunction 过滤ArrayCollection 中的数据。我现在要做的也是过滤SubCollection 中的记录,以便仅在AdvancedDataGrid 中显示与过滤器匹配的项目。

谁能告诉我如何过滤HierarchicalData 中的子行?

【问题讨论】:

  • 递归循环遍历它并将过滤器函数应用于每个子集合。
  • @RIAstar 我试过这样做。在调试过程中,我可以看到 SubCollection 在过滤后具有正确数量的项目,但 AdvancedDataGrid 仍然显示完整的项目列表。有什么建议吗?
  • 听起来在集合之后视图没有被刷新。 AdvancedDataGrid 有时可以成为皇家 PITA(嗯,大多数时候真的)。

标签: apache-flex filter flex4 flex3 hierarchical-data


【解决方案1】:

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;
}

【讨论】:

  • 迈克,你是男人!经过数小时的挫折,您的回答使我朝着正确的方向前进。谢谢。
  • 我可以再问一个问题。您的回答帮助我获得了我想要的过滤结果,但现在我在使用 AdvancedDataGrids expandAll()collapseAll() 方法时遇到了问题。你以前遇到过这种情况吗?
  • 有问题吗?我假设它不会全部打开或全部关闭,简要地看一下这个方法,它依赖于一个名为“迭代器”的属性,该属性是在 dataProvider 分配中创建的——不一步一步你可能需要查看覆盖其他方法,如canHaveChildren() 还是 hasChildren() ?同样在 HierarchicalCollectionView 中,您可能需要向 openNodes 支付详细信息。在我的应用程序中,我的最大层深度为 4 - 由于行的数量,我没有明确允许用户 expandAll - 这不是正常工作流程的一部分。
  • 再想一想。 dataProviders 本质上不是“实时更新” - 需要显式调用 refresh()。如果您在需要更新的子集合上运行过滤器,并且根据我的经验,子集合没有绑定到它的父集合(例如编辑子对象) - 不会触发父集合的 collectionchangeevent。您可能需要执行类似于我的操作,在过滤器“完成”后刷新网格上的 dataProvider。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多