深度嵌套 XML
我正在尝试从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 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 asortCompareFunction
for sorting the grid based on series number - otherwise it might throw exceptions while trying to sort.UPDATE: