开发者

Flex Type Ahead DropDownList

I need to implement multi character type ahead functionality on a DropDownList. Im using spark compon开发者_Go百科ents Flex 4.5.1.

I wish the long list to for example if I type bl

It will go to Blue not to the first B then the first L

Its a common requirement and all browsers now support it, hope its something that already exists or someone has customized a version.


Why wouldn't you use the Flex Spark ComboBox, which has the type ahead feature built right in?


You can probably customize one of the many autocompletes. I posted the following snippet in another question on how to do an autocomplete.

package autoCompleteExample
{
import mx.collections.ICollectionView;
import mx.collections.IList;    
import spark.components.ComboBox;
import spark.events.TextOperationEvent;

public class AutoCompleteExample extends ComboBox
{   
    override protected function textInput_changeHandler(event:TextOperationEvent):void{
        super.textInput_changeHandler(event);
        ICollectionView(dataProvider).refresh();
    }       
    override public function set dataProvider(value:IList):void{
        ICollectionView(value).filterFunction = defaultFilterFunction;
        super.dataProvider = value;
    }       
    private function defaultFilterFunction(item:Object):Boolean{
        return (textInput.text.toLowerCase() == String(item[labelField].toLowerCase()).substr( 0, textInput.text.length ));
    }
}
}

You can probably just change the text operation handler to select the first item AFTER the refresh. Not sure how well it would work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜