简体   繁体   English

Flex + XML + dataProvider:将数据提供者指定给ComboBox和DataGrid时出现问题

[英]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.

相关问题 柔性, <mx:Combobox> &XML:获取xml节点以指定数据提供者 - Flex, <mx:Combobox> & XML: get xml node to specify's dataprovider 在Flex DataGrid中,如何将ArrayCollection用作XML文件的dataProvider? - In Flex DataGrid, How to use ArrayCollection as a dataProvider for a XML file? 保持列顺序作为flex datagrid中的dataprovider - To keep column order as dataprovider in flex datagrid 如何将XML设置为Flex中图表的dataProvider? - How to Set XML as dataProvider for Charts in Flex? 为itemRenderer灵活设置dataProvider - Flex Setting dataProvider for an itemRenderer AS3:用于 DataGrid 的基于 XML 的 DataProvider 将列乱序 - AS3: XML Based DataProvider for DataGrid puts columns out of order Flex-如何将XML子级属性值绑定到DropDownList的dataProvider属性? - Flex - How to bind XML children attribute values to dataProvider property of a DropDownList? 使用XML数据提供程序的Horizo​​ntallist控件 - Horizontallist control with XML dataprovider 将选定的项目从DataGroup(数据提供程序是XML列表)绑定到另一个组件(FLEX 4) - Binding the selected item from DataGroup (dataprovider is an XML list) to another component (FLEX 4) 如何使用本地 XML 文件作为 Flex 4.5 中 Spark 列表控件的 DataProvider? - How do I use a local XML file as a DataProvider for a Spark List control in Flex 4.5?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM