flex combobox 实现根据输入的内容 过滤下拉菜单的内容 如何实现 ? 100分

zs841002 2008-08-23 09:53:09
如题!
combobox 的editable 属性设置为true后 ,可以在下拉按钮左面的textinput框里输入内容
现在我想根据输入的内容 自动过滤下拉框里面的内容

哪位大侠有高招 !!!

100分求!!!
...全文
3164 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
meetyourmm 2011-12-25
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 fidelhl 的回复:]
Java code


package com.cattsoft.oss.util.ui.flex.graphkit.component
{
import flash.events.Event;

import mx.collections.ArrayCollection;
import mx.controls.ComboBox;

/*……
[/Quote]

你的这个例子 还是有些bug
只能输入一次 输完之后 textInput.text的值自动选择了数据源的第一个 不能输入第二个单词 而且获得textInput焦点 使得再次输入将重新替换textInput.text的值

haoyuan1984 2010-04-30
  • 打赏
  • 举报
回复
好像单独就那样写不行!需要些一个事件吧!网上很多这样的资料!可以参考下abode官网!
weilesi 2010-04-12
  • 打赏
  • 举报
回复
谢谢 fidelhl
学习
feifeiyiwen 2009-08-19
  • 打赏
  • 举报
回复
学习
baofen14787 2009-02-11
  • 打赏
  • 举报
回复
不错
小溪 2008-11-21
  • 打赏
  • 举报
回复

package com.cattsoft.oss.util.ui.flex.graphkit.component
{
import flash.events.Event;

import mx.collections.ArrayCollection;
import mx.controls.ComboBox;

/**
* @file_name FilterComboBox.as
* @author chenjh
* @date 2008-11-14 14:03:00
* @description 可以根据用户输入过滤选项的ComboBox
*/
public class FilterComboBox extends ComboBox
{
public function FilterComboBox()
{
super();
this.editable=true;
}

override protected function textInput_changeHandler(event:Event):void{
super.textInput_changeHandler(event);
FilterByKey(event);
}

//过滤数据
private function FilterByKey(event:Event):void{
var tempDataProvider:ArrayCollection = this.dataProvider as ArrayCollection;
if (tempDataProvider == null) return;
this.dataProvider.filterFunction = filterFunction;
var tempstr:String = this.text;
if(tempDataProvider.refresh()){
this.dropdown.selectedIndex = -1;
this.dropdown.verticalScrollPosition = 0;
this.text = tempstr;
this.open();
this.textInput.setFocus();
this.textInput.setSelection(tempstr.length,tempstr.length);

}
}
private function filterFunction(item:Object):Boolean{
return item['label'].toString().indexOf(this.text)!=-1;
}

}

yangjiehuan 2008-10-29
  • 打赏
  • 举报
回复
arraycollection have the method:filter ,can get filter data;
kujioon 2008-10-16
  • 打赏
  • 举报
回复
richter9999,你好!
我用你写的上面的例子,发现它不能运行,我正好想实现这样的功能,能个完整的demo吗?
我只想要能过滤下拉框里面的内容就行,不需要从httpService里面取数据

配合它的mxml文件如何写?
richter9999 2008-09-22
  • 打赏
  • 举报
回复
package com.ait.controls
{
import com.adobe.serialization.json.JSON;

import flash.events.Event;

import mx.collections.ArrayCollection;
import mx.controls.ComboBox;
import mx.controls.listClasses.IDropInListItemRenderer;
import mx.controls.listClasses.IListItemRenderer;
import mx.core.IDataRenderer;
import mx.core.mx_internal;
import mx.events.ListEvent;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.http.mxml.HTTPService;
use namespace mx_internal;

public class HttpJsonCombobox extends ComboBox implements IDataRenderer, IDropInListItemRenderer,IListItemRenderer
{
[Bindable]
private var _dataAC:ArrayCollection;

private var _http:HTTPService;//链接
private var _url:String; //URL地址
private var _param:String; //关键字参数
private var _paramobj:Object;//参数
private var tempstr:String = '';
private var _paramFlag:Boolean = true;
private var _selectedFlag:Boolean = true;

public function HttpJsonCombobox()
{
super();
_http = new HTTPService();
}


/**
* @private
*/
override protected function createChildren():void
{
super.createChildren();
//this.addEventListener('change',FilterByKey);
//this.addEventListener(KeyboardEvent.KEY_UP,FilterByKey);
}

override protected function updateDisplayList(unscaledWidth:Number,
unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth,unscaledHeight);
if(this._paramFlag){
this.SendHttpService(this._url,this._paramobj);
this._paramFlag = false;
}

}

protected function SendHttpService(url:String, param:Object = null):void{
if(_http!=null){
_http.resultFormat = "e4x";
_http.method = "POST";
_http.url = url;
_http.addEventListener(FaultEvent.FAULT,FaultHandler);
_http.addEventListener(ResultEvent.RESULT,Callback);
_http.send(param);
}
}


//重写选择
override public function set selectedIndex(value:int):void{
if(this._selectedFlag)
super.selectedIndex = value;
this.selectionChanged = false;
this.invalidateDisplayList();
}

override public function set dataProvider(value:Object):void{
if(this._selectedFlag)
this.selectionChanged = true;
else
this.selectionChanged = false;
super.dataProvider = value;

}

//重新读取数据
public function reload():void{
this.SendHttpService(this._url,this._paramobj);
}

override protected function textInput_changeHandler(event:Event):void{
super.textInput_changeHandler(event);
FilterByKey(event);
}

//过滤数据
private function FilterByKey(event:Event):void{
this._dataAC.filterFunction = filterk;
var tempstr:String = this.text;
if(this._dataAC.refresh()){
this.dropdown.selectedIndex = -1;
this.dropdown.verticalScrollPosition = 0;
this.text = tempstr;
this.open();
this.textInput.setFocus();

}
}

private function filterk(item:Object):Boolean{
return item['label'].toString().indexOf(this.text)!=-1;
}

}
zs841002 2008-08-24
  • 打赏
  • 举报
回复
没人???
newflypig 2008-08-23
  • 打赏
  • 举报
回复
100?没看见啊,哪儿呢

4,328

社区成员

发帖
与我相关
我的任务
社区描述
多媒体/设计 Flex
社区管理员
  • Flex
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧