1

我需要搜索多个项目。到目前为止我只知道如何搜索单个项目

这是我的代码

控制器.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

当您的任何正则表达式失败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 回答
0
didMatch = record.get('transactionId').match(search) || record.get('transactionName').match(search);
于 2013-10-23T21:20:08.797 回答