I am building an application which works on data from column based database. I am getting the data as arrays where each array represents a columns in the table returned by the database. The data contain parent, child relationship. The arrays may look like that (view same index in each array as a row in a normal SQL database):
我正在构建一个应用程序,它处理基于列的数据库中的数据。我将数据作为数组获取,其中每个数组表示数据库返回的表中的列。数据包含父,子关系。数组可能看起来像这样(将每个数组中的相同索引视为普通SQL数据库中的行):
[0] empty [1] empty [2] ID-A [3] ID-B [4] ID-B <-- this represents nodes' parents
[0] ID-A [1] ID-A [2] ID-B [3] ID-C [4] ID-D <-- this represents nodes' labels
[0] 100 [1] 200 [3] 300 [4] 150 [4] 150 <-- this represents values associated with nodes
Of course they are much bigger. Up to 100000 elements. All I want to do, is create the following XML from the data I have:
当然,它们要大得多。最多100000个元素。我想要做的就是从我拥有的数据创建以下XML:
<root>
<node label="ID-A" value="300">
<node label="ID-B" value="300">
<node label="ID-C" value="150"/>
<node label="ID-D" value="150"/>
</node>
</node>
</root>
Notice that for ID-A there is only one entry at the top level, and it's value is the sum for all its entries in the array.
请注意,对于ID-A,顶层只有一个条目,它的值是数组中所有条目的总和。
I do not know the depth of the structure beforehand and any IDs or values. How do I create the XML so that I will be later able to display it in a tree control? What I want to do is iterate through array, each time adding a node for an ID if it does not exist, but just update the value (add it to the current one) if the ID exists. I can create the first layer, but I have trouble accessing and updating appropriate elements at bigger depths. Basically, how do would I add a ID-E below ID-B to the XML above, in order to achieve the following:
我事先并不知道结构的深度以及任何ID或值。如何创建XML以便以后能够在树控件中显示它?我想要做的是遍历数组,每次为ID添加一个节点(如果它不存在),但只是更新值(将其添加到当前ID)(如果ID存在)。我可以创建第一层,但是我无法在更大的深度访问和更新适当的元素。基本上,我如何将ID-B下面的ID-E添加到上面的XML中,以实现以下目的:
<root>
<node label="ID-A" value="300">
<node label="ID-B" value="300">
<node label="ID-C" value="150"/>
<node label="ID-D" value="150"/>
<node label="ID-E" value="sth"/>
</node>
</node>
</root>
Or would it maybe actually be beter to build an ArrayCollection with children from the arrays I have? I am new to Flex so I can't tell myself what would be more efficient.
或者,与我拥有的数组中的子代建立一个ArrayCollection可能实际上更糟糕吗?我是Flex的新手,所以我无法告诉自己什么会更有效率。
1 个解决方案
#1
1
Converting 100k rows into XML could be very slow and XML takes up a lot of memory, which is wasted if it's just for use as a tree data provider. If you just need to do that to view the data in a tree, perhaps you can keep it in an Array, but use a customer tree dataDescriptor to define the hierarchy. http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/controls/Tree.html#dataDescriptor
将100k行转换为XML可能会非常慢,而XML会占用大量内存,如果它只是用作树数据提供程序,则会浪费掉。如果您只需要这样做以查看树中的数据,也许您可以将其保存在数组中,但使用客户树dataDescriptor来定义层次结构。 http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/controls/Tree.html#dataDescriptor
#1
1
Converting 100k rows into XML could be very slow and XML takes up a lot of memory, which is wasted if it's just for use as a tree data provider. If you just need to do that to view the data in a tree, perhaps you can keep it in an Array, but use a customer tree dataDescriptor to define the hierarchy. http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/controls/Tree.html#dataDescriptor
将100k行转换为XML可能会非常慢,而XML会占用大量内存,如果它只是用作树数据提供程序,则会浪费掉。如果您只需要这样做以查看树中的数据,也许您可以将其保存在数组中,但使用客户树dataDescriptor来定义层次结构。 http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/controls/Tree.html#dataDescriptor