【问题标题】:as3 sorting xml data?as3排序xml数据?
【发布时间】:2010-02-13 08:10:28
【问题描述】:

我有可以加载到我的 flex 应用程序中的 xml 数据;但是,我需要按节点对其进行排序。

我正在尝试创建一个组合框或列表框,它可以显示位置列表,按字母顺序或它们所在的类别对它们进行排序...

我不知道如何格式化 xml 或如何编码 flash 文件以按位置名称按字母顺序排序,然后按一个按钮,按名称按字母顺序按类别第 1 和第 2 排序。

我应该像这样格式化 xml:

<POIs>
    <location>
            <name>Barbaras Bagels</name>
            <additional nodes inbetween here>
            <category>Restaurants</category>
    </location>
    <location>
            <name>Bobs Powerwashing</name>
            <addition nodes inbetween here>
            <category>Services</category>
    </location>
</POIs>

或者我应该像这样格式化它:

<POIs>
    <Restaurants>
        <location>
                <name>Barbaras Bagels</name>
                <additional nodes inbetween here>
        </location>
    </Restaurants>
    <Services>
        <location>
                <name>Bobs Powerwashing</name>
                <addition nodes inbetween here>
        </location>
    </Services>
</POIs>

上面的例子每个类别只有一个名字,但我相信你能理解

【问题讨论】:

    标签: xml actionscript-3 sorting combobox listbox


    【解决方案1】:

    您有一组位置对象。所以你的数组将被命名为“位置”(复数,就像你对任何数组所做的那样)。

    让您的服务器为您完成肮脏的工作。如果您只需要餐厅,则让服务器返回带有餐厅的数组。服务也是如此。如果你有很多数据,这可能会有点慢。这就是为什么 Flash Player 具有 AMF(又名 Flash Remoting)的原因,您需要什么实现取决于您的服务器技术。

    无论如何,如果您确实希望它在 XML 中交错,我想这可能是我想出的格式,我会使用 XPath 从 XML 中选择所有相关节点。

    <locations>
        <location>
                <name>Barbaras Bagels</name>
                <additional nodes inbetween here>
                <category>Restaurants</category>
        </location>
        <location>
                <name>Bobs Powerwashing</name>
                <addition nodes inbetween here>
                <category>Services</category>
        </location>
    </locations>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-07
      • 1970-01-01
      相关资源
      最近更新 更多