深度嵌套 XML

发布于 2024-08-07 19:03:36 字数 1509 浏览 10 评论 0原文

我正在尝试从 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 中,然后我有一个嵌套数据网格类,它允许我执行类似的操作。

<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 文件塞进了旁边的单元格中。

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

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>

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>

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.

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...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北斗星光 2024-08-14 19:03:36

使用 xml 的当前结构,可以更轻松地使用两列网格来表示它 - 第一列是系列号,第二列是另一个显示文件详细信息的 2 或 3 列 DataGrid。但如果您不想更改结构,则需要以下代码。请注意,由于未设置 dataField 属性,因此您必须指定 sortCompareFunction 来根据序列号对网格进行排序 - 否则在尝试排序时可能会引发异常。

<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

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;
}

UPDATE:

<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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文