Flex + XML + dataProvider : Problem specifying dataProvider to ComboBox & DataGrid
I get a XML Response from a PHP Script which I access using [lastResult] property.
The problem is the follwing: XML Structure:<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
'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.
'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.
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())
Any help is appreciated.Regards,
Nisheeth BarthwallastResult.Category1.Data.(@Name == "Data1").Item
gives you XMLList of Items found in Data1. Each item is of type XML and you can call parent()
function get parent node:
//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. Set it to this:
function formatItem(item:Object, column:DataGridColumn):String {
return (item as XML).parent().@Name;
}
精彩评论