如何使用完全匹配过滤extjs商店

问题描述 投票:4回答:3

我正在为商店使用过滤器。问题是我想要返回完全匹配。

例如:

如果我在网格中过滤aa-1,它将显示aa-1aa-1***,但如果我只想用aa-1查看所有内容。

我用它来过滤:

listeners: {
    itemclick: function() {
        var data = grid.getSelectionModel().selected.items[0].data;
        store.clearFilter();
        store.filter('productsCat', data.productsCat);
    }
}

我该怎么做才能完全匹配?

extjs filter store extjs4.1
3个回答
5
投票

您可以在过滤器中使用正则表达式来确保比较值是短语的结尾。

要么是这样,要么使用filterBy()方法来定义比较函数,例如:

store.filterBy(this, function(rec, id) {
    if(rec.get('thefieldtocompare') === "what you want to compare against") {
        return true;
    }
    else {
        return false;
    }
});

13
投票

对于ExtJS 4,您只需使用exactMatch和caseSensitive配置选项:

store.filter({
  property: fieldName,
  value: fieldValue,
  exactMatch: true,
  caseSensitive: true
})

3
投票

您没有提到您正在使用的ExtJS版本,但这里有两种常规方法:

  1. 提供具有完全匹配模式的正则表达式: qazxsw poi 要么
  2. store.filter('productsCat', new RegExp('^' + Ext.escapeRe(data.productsCat) + '$')); 提供您自己的匹配功能 filterBy
© www.soinside.com 2019 - 2024. All rights reserved.