1

假设我有一个包含以下模型结构的商店:

Ext.define('MyApp.model.FavoriteScreen', {
extend: 'Ext.data.Model',

config: {
    fields: [
        {
            name: 'Id',
            type: 'int'
        },
        {
            name: 'Key1'
        },
        {
            name: 'Key2'
        },
        {
            name: 'Key3'
        },
        {
            name: 'Key4'
        }
    ]
}

});

现在要根据 key1 从 store 中找到值,我编写了以下代码行:

var favoritStore = Ext.data.StoreManager.lookup('FavoriteStore'),
index = favoritStore.find('Key1',key_value),
filterValue = index != -1 ? favoritStore.getAt(index) : null;

它工作正常。但我想根据两个键(即 key1 和 key2)从商店中获取价值,但我不知道如何做到这一点。请给我适当的解决方案。

4

2 回答 2

2

你可以试试这个代码...

var filterValue = null;
favoritStore.each(function(record){
      if(record.get('Key1') == 'yourValue1' && record.get('Key2') == 'yourValue2') {
         filterValue = record;
      }
});
于 2013-08-19T12:42:27.280 回答
0

如果您使用商店的过滤器功能,您可以通过多个键进行过滤,然后使用 .each() 遍历过滤后的商店

store.filter([
    {property: "key1", value: "value1"},
    {property: "key2", value: "value2"}
]);

在文档中查看: http ://docs.sencha.com/touch/2.3.0/#!/api/Ext.data.Store-method-filter

于 2013-12-10T21:05:23.967 回答