Combobox Dataprovider - 仅从XML获取labelField,而不是关联的ID [英] Combobox Dataprovider - Only gets labelField from XML not the associated ID

查看:159
本文介绍了Combobox Dataprovider - 仅从XML获取labelField,而不是关联的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此时再次与数据提供商合作。

Back again this time working with data providers.

我已经做了一些与Flex的培训,我已经搜索,我设法得到一个ComboBox通过XML数据填充。它的工作相当不错,他从XML中获取每个项目的LabelField,但是与每个项目相关的ID,他没有从XML获得。

Well i been doing a bit of training with Flex, and I've searched, and i managed to get a ComboBox being populated through XML data. Its works pretty well, he gets the LabelField for each item from XML, but the ID associated to each item he doesn't get then from the XML.

代码: / p>

Code:

<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="355" height="465" creationComplete="getPaises.send();"
xmlns:ns1="com.*" title="Perfil" fontWeight="normal">

<mx:HTTPService id="getPaises" url="com-handler/paises.php" result="paisesHandler()"/>

    <mx:Script>
        <![CDATA[
            private function paisesHandler():void
            {   
                pais.dataProvider = getPaises.lastResult.paises.pais;
                pais.data = "id";
                pais.labelField = "nome";

            }
       ]]>

    </mx:Script>

<mx:ComboBox x="121" y="328" width="200" id="pais">
</mx:ComboBox>

</mx:TitleWindow>






现在来自PHP的ouput XML:


And now the ouput XML from PHP:

<?xml version="1.0" encoding="utf-8"?>
<paises>

    <pais>
        <id>1</id>
        <nome>Portugal</nome>
    </pais>

    <pais>
        <id>2</id>

        <nome>Espanha</nome>
    </pais>

</paises

从XML
< nome>< / nome> )获取国家/地区名称,但他没有放置相关的ID(< id< / id> )。

Well this is what it happens, i does gets the Country names from the XML (<nome></nome>) but he doesn't place the associated ID (<id</id>).

标签可绑定到ComboBox.selectedIndex

I now that because i placed a Label bindable to the ComboBox.selectedIndex

<mx:Label x="121" y="403" text="{pais.selectedIndex}"/>

正如你也看到我使用 pais.data =id 根据我在网络中看到的示例,它应该包括从XML到ComboBox中每个项目NOME的ID。

And as you also see i used pais.data = "id"; that according to examples i saw in the web, it should include the ID from XML to each item NOME in the ComboBox.

Flex,所以可能没有表达正确的方式。

I new to Flex, so probably didn't expressed things the right way.

任何帮助是赞赏。

推荐答案

您不需要此行:

pais.data = "id";

将标签更改为

<mx:Label x="121" y="403" text="{pais.selectedItem.id}"/>

编辑:代码可以简化为

<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" 
  width="355" height="465" creationComplete="getPaises.send();"
  xmlns:ns1="com.*" title="Perfil" fontWeight="normal">

  <mx:HTTPService id="getPaises" url="com-handler/paises.php" resultFormat="e4x"/>

  <mx:ComboBox x="121" y="328" width="200" id="pais" labelField="nome" 
    dataProvider="{XML(getPaises.lastResult).pais}"/>
</mx:TitleWindow>

编辑数据提供程序。感谢

Edited the data provider. Thanks

这篇关于Combobox Dataprovider - 仅从XML获取labelField,而不是关联的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆