【问题标题】:Flex tree control with array collection具有数组集合的 Flex 树控件
【发布时间】:2012-04-09 10:10:38
【问题描述】:

我已经为此苦苦挣扎了好几个小时!我真的需要帮助

我试图用通过 arraycollection 引入的外部 xml 文件填充树控件,但我需要将 xml 数据分组以显示在树中

好的,我的外部 xml 文件称为parts.xml,它看起来像这样:

<NewDataSet>
    <Parts>
        <PartGroup>51 Series</PartGroup>
        <PartType>20051</PartType>
        <PartNumber>20051-3</PartNumber>
        <PartDesc>Reusable Socket-51 SER</PartDesc>
        <PartImageFile />
    </Parts>
    <Parts>
        <PartGroup>51 Series</PartGroup>
        <PartType>20051</PartType>
        <PartNumber>20051-4</PartNumber>
        <PartDesc>Reusable Socket-51 SER</PartDesc>
        <PartImageFile />
    </Parts>
    <Parts>
        <PartGroup>51 Series</PartGroup>
        <PartType>20151</PartType>
        <PartNumber>20151-12-12</PartNumber>
        <PartDesc>Penis</PartDesc>
        <PartImageFile>20151-vi copy.jpg</PartImageFile>
    </Parts>
    <Parts>
        <PartGroup>90 Series</PartGroup>
        <PartType>090</PartType>
        <PartNumber>090-20B</PartNumber>
        <PartDesc>Replace Ferrule-90 SER</PartDesc>
        <PartImageFile>090 copy.jpg</PartImageFile>
    </Parts>
    <Parts>
        <PartGroup>90 Series</PartGroup>
        <PartType>090</PartType>
        <PartNumber>090-4B</PartNumber>
        <PartDesc>Replace Ferrule-90 SER</PartDesc>
        <PartImageFile>090 copy.jpg</PartImageFile>
    </Parts>
    <Parts>
        <PartGroup>90 Series</PartGroup>
        <PartType>20090</PartType>
        <PartNumber>20090-12</PartNumber>
        <PartDesc>Replacement Socket-FA</PartDesc>
        <PartImageFile>20090-vi copy.jpg</PartImageFile>
    </Parts>
    <Parts>
        <PartGroup>90 Series</PartGroup>
        <PartType>20090</PartType>
        <PartNumber>20090-12C</PartNumber>
        <PartDesc>Replacement Socket-FA, SS</PartDesc>
        <PartImageFile>20090-vi copy.jpg</PartImageFile>
    </Parts>
</NewDataSet>

这只是一个示例(实际的 xml 是 7591 行)..

下一个我正在使用

<mx:HTTPService id="getPartsXml" url="assets/db/Parts_DB.xml" result="partsDB=getPFDXml.lastResult.NewDataSet.Parts"/>

将 xml 转换为 flex。 partsDB 是一个绑定到树形控件的数组集合。

我遇到的问题是让树以我需要的方式显示数据而不会丢失任何其他数据。

我的意思是,从上面的 xml 中我需要树像这样显示

+-51 series
|  +->20051
|  |  |->20051-3
|  |  |->20051-4
|  |
|  +->20151
|     |->20151-12-12
|
+-90 Series
   +->090
   |  |->090-20B
   |  |->090-4B
   |
   +->20090
      |->20090-12
      |->20090-12C

另外,我打算让用户拥有巨大的零件树,他们在零件编号级别选择一个节点并将其拖放到数据网格上,该零件的所有其他标签都会显示在该数据网格上。

我尝试了很多事情,但没有任何运气。即使现在我在想,如果我循环遍历数组集合并为树创建一个新数组以使其以我需要的方式显示,那么当用户将一个部分拖放到网格上时,我会有代码将在原始数组集合中查找该零件号并将其添加到仅用于数据网格的新数组中...我仍然不知道如何为树创建该新数组!导致 xml 数据先按 partgroup 分组,然后再按 parttype 分组,然后再获得各个零件编号:(

我希望这是有道理的

【问题讨论】:

    标签: xml apache-flex tree arraycollection


    【解决方案1】:

    您有 2 个组件。 第一个(树)没有正确显示数据:

    1. 树需要分层数据。您的 XML 数据是平面的(但在数组集合中)。将其与GroupingCollection2 分组。
    2. 或者使用 AdvancedDataGrid 模拟树形控件,如this

    就数据网格而言,您最有可能让它与自己的集合一起工作,但从您的第一个组件的集合中获取对象:

    1. 从 1 到 2 双击/拖放会导致插入 2 的集合(并检查它是否已经存在)
    2. 您可能还需要包含一种从 2 中删除的方法,否则您将拥有一个始终填充且永远不会清除的组件。

    【讨论】:

      猜你喜欢
      • 2011-11-01
      • 1970-01-01
      • 2011-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-30
      • 1970-01-01
      相关资源
      最近更新 更多