Flex-combobox-control

提供:Dev Guides
移動先:案内検索

Flex-ComboBoxコントロール

ユーザーがComboBoxコントロールのドロップダウンリストからアイテムを選択すると、データアイテムがコントロールのプロンプト領域に表示されます。

ComboBoxコントロールとDropDownListコントロールの違いの1つは、ComboBoxコントロールのプロンプト領域がTextInputコントロールを使用して実装されているのに対し、DropDownListコントロールの場合はLabelコントロールです。 したがって、ユーザーはコントロールのプロンプト領域を編集して、使用可能なオプションの1つではない値を入力できます。

クラス宣言

以下は spark.components.ComboBox クラスの宣言です-

public class ComboBox
   extends DropDownListBase
      implements IIMESupport

パブリックプロパティ

Sr.No Property & Description
1

enableIME : Boolean

[読み取り専用]

2 *imeMode : String *
3
  • itemMatchingFunction : Function = null*

ユーザーがプロンプト領域に文字を入力するときに項目リストを検索するために使用されるコールバック関数を指定します。

4

labelToItemFunction : Function

プロンプト領域に入力された新しい値を、データプロバイダーのデータ項目と同じデータ型に変換するコールバック関数を指定します。

5

maxChars : int

ユーザーが入力した、プロンプト領域に含めることができる最大文字数。

6

openOnInput : Boolean = true

trueの場合、ユーザーがプロンプト領域を編集すると、ドロップダウンリストが開きます。

7

prompt : String

入力テキストがnullの場合に表示されるテキスト。

8

restrict : String

ユーザーがプロンプト領域に入力できる文字のセットを指定します。

パブリックメソッド

Sr.No Method & Description
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
  • 対象

Flex ComboBoxコントロールの例

次の手順に従って、テストアプリケーションを作成して、FlexアプリケーションでのComboBoxコントロールの使用を確認します。

Step Description
1 Create a project with a name HelloWorld under a packagecom.finddevguides.client as explained in the Flex - Create Application chapter.
2 Modify HelloWorld.mxml as explained below. Keep rest of the files unchanged.
3 Compile and run the application to make sure business logic is working as per the requirements.

以下は、変更されたmxmlファイルの内容です src/com.finddevguides/HelloWorld.mxml

<?xml version = "1.0" encoding = "utf-8"?>
<s:Application xmlns:fx = "http://ns.adobe.com/mxml/2009"
   xmlns:s = "library://ns.adobe.com/flex/spark"
   xmlns:mx = "library://ns.adobe.com/flex/mx"
   width = "100%" height = "100%" minWidth = "500" minHeight = "500">

   <fx:Style source = "/com/finddevguides/client/Style.css"/>
   <fx:Script>
      <![CDATA[
         import mx.collections.ArrayCollection;

         [Bindable]
         public var data:ArrayCollection = new ArrayCollection (
         [
            {value:"France", code:"FR"},
            {value:"Japan", code:"JP"},
            {value:"India", code:"IN"},
            {value:"Russia", code:"RS"},
            {value:"United States", code:"US"}
         ]
         );

         private function mappingFunction(input:String):Object {
            switch (input){
               case "France":
                  return {value:input, code:"FR"};
               case "Japan":
                  return {value:input, code:"JP"};
               case "India":
                  return {value:input, code:"IN"};
               case "Russia":
                  return {value:input, code:"RS"};
               case "United States":
                  return {value:input, code:"US"};
            }
            return null;
         }

      ]]>
   </fx:Script>

   <fx:Declarations>
      <mx:DateFormatter id = "dateFormatter"/>
   </fx:Declarations>

   <s:BorderContainer width = "550" height = "400" id = "mainContainer"
      styleName = "container">
      <s:VGroup width = "100%" height = "100%" gap = "50" horizontalAlign = "center"
         verticalAlign = "middle">
         <s:Label id = "lblHeader" text = "Form Controls Demonstration"
            fontSize = "40" color = "0x777777" styleName = "heading"/>

         <s:Panel id = "comboBoxPanel" title = "Using ComboBox" width = "420"
            height = "200">
         <s:layout>
            <s:VerticalLayout  gap = "10" verticalAlign = "middle"
               horizontalAlign = "center"/>
         </s:layout>

         <s:HGroup>
            <s:Label text = "Index :"/> <s:Label
               text = "{comboBox.selectedIndex}" fontWeight = "bold"/>
            <s:Label text = "Value :"/> <s:Label
               text = "{comboBox.selectedItem.value}" fontWeight = "bold"/>
            <s:Label text = "Code :"/> <s:Label
               text = "{comboBox.selectedItem.code}" fontWeight = "bold"/>
         </s:HGroup>

         <s:ComboBox  id = "comboBox"  dataProvider = "{data}" width = "150"
            labelToItemFunction = "{mappingFunction}" selectedIndex = "0"
            labelField = "value"/>
         </s:Panel>
      </s:VGroup>
   </s:BorderContainer>
</s:Application>

すべての変更が完了したら、link:/flex/flex_create_application [Flex-アプリケーションの作成]の章で行ったように、アプリケーションを通常モードでコンパイルして実行します。 アプリケーションに問題がなければ、次の結果が生成されます。[link:/flex/samples/FormControlsApplicationl#currentlyLoaded = ComboBox [Try it online]]

Flex ComboBox Control