过滤商店记录 - 不同

时间:2012-09-06 18:30:33

标签: extjs extjs4

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

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

上述代码将过滤所有名称为SAM的名称。但是,我想要它返回1个名称(只有SAM(一次))。

例如,在数据库中,我们使用关键字 DISTINCT 来获取1条记录(如果有多个)。我怎么能在我的场景中做到这一点?

1 个答案:

答案 0 :(得分: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();
相关问题