根据用户输入过滤数据提供者的组合框 [英] combobox which filters dataprovider based on user input

查看:18
本文介绍了根据用户输入过滤数据提供者的组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个基于用户输入过滤数据提供者的组合框?

I need a combobox which filters dataprovider based on user input?

例如,如果用户输入是CA"组合框将过滤数据提供者并仅显示以CA"开头的数据.(加拿大"和加利福尼亚")

For example if user input is "CA" combobox will filter the dataprovider and show only data which starts with "CA". ("CANADA" and "CALIFORNİA")

注意:组合框是可编辑的.

note:combobox is editable.

我在 flex 3 中需要这个组合框.

and ı need this combobox in flex 3.

好的,我从 javaluca 那里得到了一些帮助,我写了这个.

edit:okay ı got some help from javaluca and ı wrote this.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" 
    creationComplete="createCompFonk()">
    <mx:Script>
     <![CDATA[
        import mx.controls.Text;
        import mx.controls.dataGridClasses.DataGridColumn;
     import mx.controls.TextInput;
 import mx.events.ItemClickEvent;
 import mx.events.DataGridEvent;
 import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.collections.ListCollectionView; 
import mx.controls.ComboBox

     var sayac:int=0;
     var degisken:String;

     [Bindable]
     private var initDG:ArrayCollection = new ArrayCollection([ {islem:'Tahsilat112', tarih:'01/01/2000', isim:'ATA'},{islem:'Ödeme', tarih:'02/03/2010', isim:'BETA'}      ]);




      public function createCompFonk():void{
        gggcombo.textInput.addEventListener(TextEvent.TEXT_INPUT, textChange);

      }
    protected function textChange(evt:TextEvent):void{
    (gggcombo.dataProvider as ArrayCollection).filterFunction = filterFunc;
    (gggcombo.dataProvider as ArrayCollection).refresh();
    // REFRESH IS NECESSARY
}

public function filterFunc(item:Object):Boolean{
    var pattern:String = gggcombo.textInput.text.toLowerCase();
    var string:String = item.islem;

    return pattern == string.substr( 0, pattern.length );
}
        ]]>
      </mx:Script>


  <mx:Panel x="0" y="0" width="435" height="216" 
      layout="absolute" title="Empty Default Datagrid">


   <mx:ComboBox id="gggcombo" dataProvider="{initDG}" labelField="islem" editable="true"  >


   </mx:ComboBox>
  </mx:Panel>


</mx:Application>

但是我在这些行上出错了:

but ı got an error on these rows :

gggcombo.textInput.addEventListener(TextEvent.TEXT_INPUT, textChange);

 var pattern:String = gggcombo.textInput.text.toLowerCase();

错误是:尝试通过静态类型 mx.controls:comboBox 的引用访问不可访问的属性 textInput

Error is : Attempted acces of inaccesible property textInput through a reference with static type mx.controls:comboBox

推荐答案

如果您使用 ArrayCollection Class for combobox dataprovider,则可以使用 filterFunction.

If you are using ArrayCollection Class for combobox dataprovider, you can use the filterFunction.

在包含在组合中的 textInput 添加侦听器

Add listener on textInput that is contained into the combo

myCombo.textInput.addEventListener(TextEvent.TEXT_INPUT, textChange);

在 textChange 上调度的函数

Function dispatched on the textChange

protected function textChange(evt:TextEvent):void{
    (myCombo.dataProvider as ArrayCollection).filterFunction = filterFunc;
    (myCombo.dataProvider as ArrayCollection).refresh();
    // REFRESH IS NECESSARY
}

FilterFunction 用于过滤 dataProvider

FilterFunction for filtering dataProvider

public function filterFunc(item:Object):Boolean{
    var pattern:String = myCombo.textInput.text.toLowerCase();
    var string:String = item.name;

    return pattern == string.substr( 0, pattern.length );
}

这篇关于根据用户输入过滤数据提供者的组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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