[英]Flex + XML + dataProvider : Problem specifying dataProvider to ComboBox & DataGrid
I get a XML Response from a PHP Script which I access using [lastResult] property. 我从使用[lastResult]属性访问的PHP脚本获得了XML响应。
The problem is the follwing: 问题在于:
XML Structure: XML结构:
<Main>
<Category1>
<Data Name="Data1">
<Item>
<Name>foo</Name>
<Info>bar</Info>
</Item>
<Item>
<Name>baz</Name>
<Info>FOO</Info>
</Item>
</Data>
<Data Name="Data2">
</Data>
</Category1>
<Category2>
</Category2>
</Main>
Now I specify the dataProvider for the DataGrid as 现在,我将DataGrid的dataProvider指定为
'lastResult.Category1.Data.(@Name == "Data1").Item'
This works fine enough & my data is correctly outputted. 这足够正常,并且我的数据已正确输出。 The only thing I need is that how can I access the @Name property of the
<Data>
tag. 我唯一需要的是如何访问
<Data>
标记的@Name属性。
I can output Name & Info of Items by specifying: 我可以通过指定输出项目的名称和信息:
'Name'
'Info'
But I'm clueless how to specify the @Name attribute of the parent <Data>
tag when I've selected Data.Item as the dataProvider. 但是,当我选择Data.Item作为dataProvider时,我不知道如何指定父
<Data>
标记的@Name属性。
From what I can make of it, I need to go up 1 level to the parent node, but I couldn't find any reference so as how to go up one level while using [lastResult] dataProvider (all were using XMLListCollection::parent()) 据我所知,我需要上一级到父节点,但是我找不到任何引用,以便在使用[lastResult] dataProvider时如何上一层(所有这些都在使用XMLListCollection :: parent ())
Any help is appreciated. 任何帮助表示赞赏。
Regards, 问候,
Nisheeth Barthwal 尼希普·巴思沃尔
lastResult.Category1.Data.(@Name == "Data1").Item
gives you XMLList of Items found in Data1. lastResult.Category1.Data.(@Name == "Data1").Item
为您提供在Data1中找到的项的XMLList。 Each item is of type XML and you can call parent()
function get parent node: 每个项目都是XML类型,您可以调用
parent()
函数获取父节点:
//get first item
var item:XML = lastResult.Category1.Data.(@Name == "Data1").Item[0];
trace("Data.@Name: " + item.parent().@Name);
Edit: to make it work inside DataGrid, you need to use labelFunction
property of column. 编辑:要使其在DataGrid中工作,您需要使用列的
labelFunction
属性。 Set it to this: 设置为此:
function formatItem(item:Object, column:DataGridColumn):String {
return (item as XML).parent().@Name;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.