课程表

Flex课程

工具箱
速查手册

Flex ComboBox控件

当前位置:免费教程 » 软件/图像 » Flex

介绍

当用户从ComboBox控件中的下拉列表中选择一个项目时,数据项将显示在控件的提示区域中。

ComboBox和DropDownList控件之间的一个区别是ComboBox控件的提示区域是通过使用TextInput控件实现的,而在DropDownList控件的情况下,它是Label控件。 因此,用户可以编辑控件的提示区域,以输入不是可用选项之一的值。

类声明

以下是 spark.components.ComboBox 类的声明:

  1. public class ComboBox
  2. extends DropDownListBase
  3. implements IIMESupport

公共财产

S.N.属性和描述
1

enableIME:Boolean

[只读]

2

imeMode:String

3

itemMatchingFunction:Function = null

指定用于在用户在提示区域中输入字符时用于搜索项目列表的回调函数。

4

labelToItemFunction:Function

指定回调函数,将输入提示区域的新值转换为与数据提供者中的数据项相同的数据类型。

5

maxChars:int


The maximum number of characters that the prompt area can contain, as entered by a user.
6

openOnInput:Boolean = true

如果为true,则当用户编辑提示区域时,下拉列表将打开。

7

prompt : String

如果/当输入文本为null时要显示的文本。

8

restrict:String

指定用户可以在提示区域中输入的字符集。

公共方法

S.N.方法和描述
1

ComboBox()

构造函数。

继承的方法

此类继承以下类中的方法:

  • spark.components.supportClasses.DropDownListBase

  • spark.components.List

  • spark.components.supportClasses.ListBase

  • spark.components.SkinnableDataContainer

  • spark.components.supportClasses.SkinnableContainerBase

  • spark.components.supportClasses.SkinnableComponent

  • mx.core.UIComponent

  • mx.core.FlexSprite

  • flash.display.Sprite

  • flash.display.DisplayObjectContainer

  • flash.display.InteractiveObject

  • flash.display.DisplayObject

  • flash.events.EventDispatcher

  • Object

Flex组合框控件示例

让我们按照以下步骤通过创建测试应用程序来检查Flex应用程序中ComboBox控件的使用:

步骤描述
1 Flex - 创建应用程序章节中所述,在包 com.tutorialspoint.client 下创建名为 HelloWorld 的项目。
2修改 HelloWorld.mxml ,如下所述。 保持文件的其余部分不变。
3编译并运行应用程序,以确保业务逻辑按照要求工作。

以下是修改的mxml文件的内容 src / com.tutorialspoint / HelloWorld.mxml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
  3. xmlns:s="library://ns.adobe.com/flex/spark"
  4. xmlns:mx="library://ns.adobe.com/flex/mx"
  5. width="100%" height="100%" minWidth="500" minHeight="500"
  6. >
  7.  
  8. <fx:Style source="/com/tutorialspoint/client/Style.css"/>
  9.  
  10. <fx:Script>
  11. <![CDATA[
  12. import mx.collections.ArrayCollection;
  13.  
  14. [Bindable]
  15. public var data:ArrayCollection = new ArrayCollection(
  16. [
  17. {value:"France", code:"FR"},
  18. {value:"Japan", code:"JP"},
  19. {value:"India", code:"IN"},
  20. {value:"Russia", code:"RS"},
  21. {value:"United States", code:"US"}
  22. ]
  23. );
  24.  
  25. private function mappingFunction(input:String):Object
  26. {
  27. switch (input){
  28. case "France":
  29. return {value:input, code:"FR"};
  30. case "Japan":
  31. return {value:input, code:"JP"};
  32. case "India":
  33. return {value:input, code:"IN"};
  34. case "Russia":
  35. return {value:input, code:"RS"};
  36. case "United States":
  37. return {value:input, code:"US"};
  38. }
  39. return null;
  40. }
  41.  
  42. ]]>
  43. </fx:Script>
  44. <fx:Declarations>
  45. <mx:DateFormatter id="dateFormatter" />
  46. </fx:Declarations>
  47. <s:BorderContainer width="550" height="400" id="mainContainer"
  48. styleName="container">
  49. <s:VGroup width="100%" height="100%" gap="50" horizontalAlign="center"
  50. verticalAlign="middle">
  51. <s:Label id="lblHeader" text="Form Controls Demonstration"
  52. fontSize="40" color="0x777777" styleName="heading"/>
  53. <s:Panel id="comboBoxPanel" title="Using ComboBox" width="420"
  54. height="200">
  55. <s:layout>
  56. <s:VerticalLayout gap="10" verticalAlign="middle"
  57. horizontalAlign="center"/>
  58. </s:layout>
  59. <s:HGroup>
  60. <s:Label text="Index :"/> <s:Label
  61. text="{comboBox.selectedIndex}" fontWeight="bold"/>
  62. <s:Label text="Value :"/> <s:Label
  63. text="{comboBox.selectedItem.value}" fontWeight="bold"/>
  64. <s:Label text="Code :"/> <s:Label
  65. text="{comboBox.selectedItem.code}" fontWeight="bold"/>
  66. </s:HGroup>
  67. <s:ComboBox id="comboBox" dataProvider="{data}" width="150"
  68. labelToItemFunction="{mappingFunction}" selectedIndex="0"
  69. labelField="value"/>
  70. </s:Panel>
  71. </s:VGroup>
  72. </s:BorderContainer>
  73. </s:Application>

准备好所有更改后,让我们以正常模式编译和运行应用程序,就像在 Flex - 创建应用程序中一样 章节。 如果一切顺利,您的应用程序,这将产生以下结果:[在线试用]

Flex ComboBox Control
转载本站内容时,请务必注明来自W3xue,违者必究。
 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号