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

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

问题描述

这次再次与数据提供者合作.

Back again this time working with data providers.

嗯,我一直在用 Flex 进行一些培训,我已经搜索过了,我设法通过 XML 数据填充了一个 ComboBox.它工作得很好,他从 XML 中获取了每个项目的 LabelField,但是他没有从 XML 中获取与每个项目相关联的 ID.

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.

代码:

<?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 的输出 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 中获取了国家/地区名称() 但他没有放置关联的 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天全站免登陆