简体   繁体   中英

How can I Check if a TextInput has a Text to Search in Flex?

im trying to search into a IconsGroup in my application some elements with a "code", using a TextInput and validating if contains the code of any icons in the group.

if(iconsGroup.numElements > 0) {
  for(var i:int = 0; i<iconsGroup.numElements; i++) {
     if(iconsGroup.getElementAt(i) is R_VO) { 
        if((iconsGroup.getElementAt(i) as R_VO)._extintores != null 
           && (txtBuscar.text.indexOf((iconsGroup.getElementAt(i) as R_VO)._extintores._codigo)) > -1) {
    shake_AfterSearch(i);
        }
     }
}

But my problem right now is if I search a text:

"Code_1"

and

"CODE_1"

Exists a way to search it and find both Icons with the code "Code_1" or "CODE_1"?, I want to search it without case sensitive

You just need to use toLowerCase() on strings. In your case it will be looked next:

var buscarText:String = txtBuscar.text.toLowerCase();
var searchedText:String;

if(iconsGroup.numElements > 0) {
  for(var i:int = 0; i<iconsGroup.numElements; i++) {
     searchedText = (iconsGroup.getElementAt(i) as R_VO)._extintores._codigo.toLowerCase();
     if(iconsGroup.getElementAt(i) is R_VO) { 
        if((iconsGroup.getElementAt(i) as R_VO)._extintores != null 
           && (buscarText.indexOf(searchedText)) > -1) {
            shake_AfterSearch(i);
        }
     }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM