2013-03-07 3 views
1

여러 품목을 검색해야합니다. 지금까지 나는 단지 여기에 내 코드여러 항목 검색 sencha touch

Controller.js

onSearchKeyUp: function (field) { 
    //get the store and the value of the field 
    var value = field.getValue(), 
     store = Ext.getCmp('transactionlist').getStore();  

    //first clear any current filters on thes tore 
    store.clearFilter(); 

    //check if a value is set first, as if it isnt we dont have to do anything 
    if (value) { 
    //the user could have entered spaces, so we must split them so we can loop through them all 
    var searches = value.split(' '), 
    regexps = [], 
    i; 

    //loop them all 
    for (i = 0; i < searches.length; i++) { 
     //if it is nothing, continue 
     if (!searches[i]) continue; 

     //if found, create a new regular expression which is case insenstive 
     regexps.push(new RegExp(searches[i], 'i')); 
    } 

    //now filter the store by passing a method 
    //the passed method will be called for each record in the store 
    store.filter(function (record) { 
     var matched = []; 

     //loop through each of the regular expressions 
     for (i = 0; i < regexps.length; i++) { 
     var search = regexps[i], 
     didMatch = record.get('transactionId').match(search) ; 

     //if it matched the first or last name, push it into the matches array 
     matched.push(didMatch); 
     } 

     //if nothing was found, return false (dont so in the store) 
     if (regexps.length > 1 && matched.indexOf(false) != -1) { 
     return false; 
     } else { 
     //else true true (show in the store) 
     return matched[0]; 
     } 
    }); 
    } 
}, 

방법 여러 항목을 검색하는 나를 인도 해주십시오입니다 단일 항목

을 검색하는 방법을 알고있다. 감사합니다

답변

0

정규식 중 실패하면 false을 반환하는 것 같습니다. 귀하의 질문을 정확하게 이해하면 입력 값 중 인 경우 을 잡으려고하므로 모두이 실패 할 때만 false을 반환해야합니다.

시도의 변화 :

if (regexps.length > 1 && matched.indexOf(true) != -1) { 
    return false; 

하고 도움이되는지 확인 :

if (regexps.length > 1 && matched.indexOf(false) != -1) { 
    return false; 

합니다.

0
didMatch = record.get('transactionId').match(search) || record.get('transactionName').match(search); 
관련 문제