简体   繁体   English

Ext JS在商店中查找具有相同属性的记录

[英]Ext js find records in store with same atribute

How can I browse a store and find the number of records which have one attribute the same? 如何浏览商店并查找具有一个属性相同的记录数? I have tired filterBy but there you can only enter a concrete value not an attribute 我已经厌倦了filterBy但是您只能输入一个具体的值而不是一个属性

Let's say I have this records: 假设我有以下记录:

record1{
name: 'John'
}
record2{
name'John'
}
record3{
name:'Steve'
}

Return the records with the same name 返回同名记录

Just loop over the collection: 只需遍历集合:

var seen = {};
store.each(function(rec) {
    var name = rec.get('name');
    if (!seen.hasOwnProperty(name)) {
        seen[name] = 0;
    }
    ++seen[name];
});

You might also be interested by Grouping : 您可能还会对Grouping感兴趣:

var myStore = Ext.create('Ext.data.Store', {
    groupField: 'name',
    groupDir  : 'DESC'
});

myStore.getGroups(); // returns:
[
    {
        name: 'yellow',
        children: [{
            name: 'John'
        }, {
            name: 'John'
        }]
    },
    {
        name: 'Steve',
        children: [{
            name: 'Steve'
        }]
    }
]

Then you can count how many children there is in each group. 然后,您可以计算每个组中有多少个孩子。

(More details here: http://docs.sencha.com/extjs/4.2.0/#!/api/Ext.data.Store ) (此处有更多详细信息: http : //docs.sencha.com/extjs/4.2.0/#!/api/Ext.data.Store

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM