深嵌套 XML [英] Deep Nested XML

查看:23
本文介绍了深嵌套 XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 XMLList 显示数据网格中的项目列表.

I am trying to display a list of items in a datagrid from an XMLList.

<Series no="1">
    <file>
        <filenum>1</epnum>
        <prodnum>4V01</prodnum>
        <title>Series #1 - File #1</title>
    </file>
    <file>
        <filenum>2</epnum>
        <prodnum>4V02</prodnum>
        <title>Series #1 - File #2</title>
    </file>
</Series>
<Series no="2">
    <file>
        <filenum>1</epnum>
        <prodnum>4V01</prodnum>
        <title>Series #2 - File #1</title>
    </file>
    <file>
        <filenum>2</epnum>
        <prodnum>4V02</prodnum>
        <title>Series #2 - File #2</title>
    </file>
</Series>

我当前的代码允许我将每个系列检索到一个 XMLList 中,然后我有一个 Nesteddatagrid 类,它允许我做类似的事情.

My current code allows me to retrieve every Series into an XMLList and then i have a nesteddatagrid class that allows me to do things like.

<classes:NestedDataGrid width="100%" height="100%" id="gridFiles" dataProvider="{filesList}" >
<classes:columns>
<mx:DataGridColumn headerText="Season" dataField="@no" width="60"/>
<mx:DataGridColumn headerText="Episode" dataField="file.filenum" width="60"/>
<mx:DataGridColumn headerText="Title" dataField="file.title"/>
</classes:columns>
</classes:NestedDataGrid>

然而,这显示了具有两行的数据网格,第一行在系列列中有 1,然后两个文件塞入同一行的第二个单元格中.第二行是相同的,但在系列列中有数字 2,两个系列 #2 文件挤在它旁边的单元格中.

However this displays the datagrid with two rows, the first row has 1 in the Series column and then the two files crammed into the second cell in the same row. The second row is the same but has the number 2 in the Series column and the two series #2 files crammed into the cell next to it.

如果我不使用嵌套数据类,我可以使用 Series.file 拉取文件,并且所有 4 个文件都正确列出,但是我没有得到每个的序列号...

If i do not use the nested data class i can pull the files using Series.file instead and all 4 of the files list correctly, however i do not get the Series number for each...

推荐答案

使用 xml 的当前结构,用两列网格表示它更容易 - 第一列是序列号,第二列是另外 2 或显示文件详细信息的 3 列 DataGrid.但是如果你不想改变结构,下面的代码就是你所需要的.请注意,由于未设置 dataField 属性,您必须指定一个 sortCompareFunction 来根据序列号对网格进行排序 - 否则在尝试排序时可能会抛出异常.>

With the current structure of the xml, it's easier to represent it with a two column grid - first column being the series number, and second column being another 2 or 3 column DataGrid that displays file details. But if you don't wanna change the structure, the following code is what you need. Note that since dataField property is not set, you have to specify a sortCompareFunction for sorting the grid based on series number - otherwise it might throw exceptions while trying to sort.

<classes:NestedDataGrid width="100%" height="100%" id="gridFiles" 
  dataProvider="{filesList.Series.file}" >
  <classes:columns><!-- classes copy pasted from OP's code. Whats that? -->
    <mx:DataGridColumn headerText="Season" labelFunction="getSeries" width="60"/>
    <mx:DataGridColumn headerText="Episode" dataField="filenum" width="60"/>
    <mx:DataGridColumn headerText="Title" dataField="title"/>
  </classes:columns>
</classes:NestedDataGrid>
private function getSeries(item:Object, col:DataGridColumn):String
{
  return XML(item).parent().@no;
}

<小时>

更新:

<mx:DataGrid width="100%" height="100%" id="gridFiles" > 
  <mx:columns>
    <mx:DataGridColumn headerText="Season" labelFunction="getSeries" width="60"/>
    <mx:DataGridColumn headerText="Episode" dataField="epnum" width="60"/>
    <mx:DataGridColumn headerText="Title" dataField="title"/>
  </mx:columns>
</mx:DataGrid>

gridFiles.dataProvider = XML(event.result).descendants('episode');
//use the same getSeries function as above

这篇关于深嵌套 XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆