开发者

RegExp search field for filter function in flex

I have a datagrid and a search field. I've set the change event of the search field to run the filterfunction of the datagrid. I'm able to match the entire term, but I'd like to be able to use a regular expression to do a progressive search (e.g., "Pe" matches "Peter"). I tried to create a regular expression to compare the fields, but I can't seem to get it to work. How do I return the results of the RegExp? Here's the function as it currently stands

private function usersFilter(item:XML):Boolean {
    var searchResult:XMLList;
    var searchCheck:RegExp = /[^a-zA-Z]*/
    var searchTerm:Object = searchCheck.exec(searchInput.text);
    searchResult = item.(firstName==searchTerm.result);
    if (searchResult.length() > 0) {
           return true;
    } else {
        return false;
 开发者_JS百科   }
}


I got it! What I wanted to do was to use the "match" function, which is a method of the String object that can take a regular expression as the pattern being matched. So, in order to match items in the dataGrid with a case-INsensitive version of the searchInput.text, I used the following code (matching against the first and last name values of the dataGrid)

private function usersFilter(item:XML):Boolean {
    var searchResult:XMLList;
    var myTest:RegExp = new RegExp(searchInput.text,"i");
    searchResult = item.(firstName.match(myTest)||lastName.match(myTest));
    if (searchResult.length() > 0) {
        return true;
    } else {
        return false;
    }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜