过滤商店记录 - 不同

Ill*_*lep 1 extjs extjs4

我正在获取一些记录,并使用如下所示的filter属性;

store = Ext.getStore('PEOPLE');
store.on('load', function() {
    store.filter({
        filterFn: function(f) {
            return f.get('Name') == "SAM"; 
        }
    });
});
store .load();
Run Code Online (Sandbox Code Playgroud)

上面的代码将过滤所有具有该名称的Name SAM.但是,我希望它只有返回1名(仅仅只有SAM(一次)).

例如,在数据库中,我们使用关键字DISTINCT只获得1条记录(如果有多个).我怎么能在我的场景中这样做?

Rei*_*ius 5

这可能是你想要的吗?

store = Ext.getStore('PEOPLE');
store.on('load', function() {
    store.filter({
        filterFn: function(f) {
            return f.get('Name') == "SAM"; 
        }
    });
    if(store.getTotalCount() > 1)
        store.remove(store.getRange(1));
});
store.load();
Run Code Online (Sandbox Code Playgroud)