1

複数のアイテムを検索する必要があります。これまでのところ、私は単一のアイテムを検索する方法しか知りません

これが私のコードです

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];
      }
    });
  }
},

複数のアイテムを検索する方法を教えてください。ありがとう

4

2 に答える 2

0
didMatch = record.get('transactionId').match(search) || record.get('transactionName').match(search);
于 2013-10-23T21:20:08.797 に答える
0

正規表現のいずれかfalseが失敗すると、戻ってくるようです。私があなたの質問を正しく理解していれば、入力値のいずれかをキャッチしたいので、すべてが失敗した場合にのみ戻る必要があります。false

変更してみてください:

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

に:

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

そして、それが役立つかどうかを確認してください。

于 2013-03-08T06:25:56.580 に答える