ActionScript - 使用 Array.sortOn() 对 XML 文件进行排序?
我需要对一个大的 XML 文件进行排序,并且我一直在阅读将每个元素放入数组中是使用 Array 的 sortOn() 方法对数据进行排序的方法。
我担心速度。也许将它们存储到 Vector 中。 XML>代替数组是否会稍微提高速度,但这种方法是对 XML 数据进行排序的最佳方法吗?
i need to sort a large XML file and i've been reading that placing each of the elements into an array is the way to sort the data using Array's sortOn() method.
i'm concerned about speed. perhaps storing them into a Vector.< XML > instead of an Array will offer a slight increase in speed, or not, but is this approach the best way to sort XML data?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
实际上,我看到两种解决方案:
1/您加载静态 xml 文件,因此您可以手动进行排序。
2/ 您加载动态 xml 并为了提高速度,服务器端可以提供排序(在 PHP 中很容易)。
我认为这是更好的做法。
因此,在这两种情况下,您必须解析一次 xml,存储数据(向量、值对象)并通过销毁对 xml 的引用来清除内存。
如果你想在 Flash 端排序,你必须创建自己的函数,并且使用 sortOn 方法似乎是不可避免的。
Actually, I see two solutions :
1/ You load a static xml file and therefore you can do sorting manually.
2/ You load a dynamic xml and to gain speed, server side can provide sorting (easily in PHP).
i think this is the better thing to do.
So in the two case, you have to parse your xml once, store data (Vector, Value Object) and clear the memory by destroying the reference to your xml.
If you want to sort on Flash side, you have to create your own function and using the method sortOn seems inevitable.
@TheDarklnl1978 以下是 fl.data.DataProvider 的部分源代码,用于转换数组中的 XML(位于 Flash CS5 安装目录中):
@TheDarklnl1978 Here is part of the source code from fl.data.DataProvider that transform an XML in an Array (found in Flash CS5 install directory):
因此,为了回答我自己的问题,我相信使用 XML 创建 DataProvider 对象是最好的解决方案。
将 XML 分配给 DataProvider 不需要设置和迭代循环,尽管幕后可能发生内部循环。我很想知道它是否有效,所以如果您知道,请发表评论。
此外,DataProvider 对象还支持排序、检索以及创建列表、数据网格等的灵活性。
so, to answer my own question, i believe that creating a DataProvider object with the XML is the best solution.
assigning the XML to the DataProvider doesn't require setting up and iterating thru a loop, although there may be an internal loop happening behind the scenes. i would be interested to know if it does or not, so please leave a comment if you know.
additionally, DataProvider objects also support sorting, retrieval and flexibility for the creation of lists, data grids, etc.