Sencha touch 2 从存储中检索值

Sencha touch 2 从存储中检索值,sencha-touch-2,Sencha Touch 2,我有以下商店: Ext.define('Sencha.model.MenuPoint', { extend: 'Ext.data.Model', config: { fields: [ {name: 'id', type: 'string'}, // this is id of the element, example child id, report id, and so fourth //{name: 'elementId', typ

我有以下商店:

Ext.define('Sencha.model.MenuPoint', {
extend: 'Ext.data.Model',

config: {
    fields: [
        {name: 'id', type: 'string'},
        // this is id of the element, example child id, report id, and so fourth
        //{name: 'elementId', type: 'int'},
        {name: 'name', type: 'string'},
        {name: 'icon_url', type: 'string'},
        {name: 'xtype', type: 'string'}
    ]
}
});
我可以像这样插入和检索值:

var keyValue = new Object();
keyValue.key = "adultId";
keyValue.value = adultObj.adultId;
console.log("keyValue: "+keyValue);
var sessionStore = Ext.getStore('MySessionStore');
sessionStore.add(keyValue);
sessionStore.sync();

var index = sessionStore.find('key',keyValue.key);
console.log("index: "+index);
var keyValue2 = sessionStore.getAt(index);
console.log("keyValue2: "+keyValue2);
var value = store.get(key);
但是,首先获取索引,然后获取值是如此的麻烦,难道不可能这样做:

var keyValue = new Object();
keyValue.key = "adultId";
keyValue.value = adultObj.adultId;
console.log("keyValue: "+keyValue);
var sessionStore = Ext.getStore('MySessionStore');
sessionStore.add(keyValue);
sessionStore.sync();

var index = sessionStore.find('key',keyValue.key);
console.log("index: "+index);
var keyValue2 = sessionStore.getAt(index);
console.log("keyValue2: "+keyValue2);
var value = store.get(key);

?

您可以使用函数

var record = store.findRecord('id', key)
这是通往成功的捷径

index = store.find('id', key);
record = index != -1 ? store.getAt(index) : null;
干杯,奥列格使用

store.findRecord('id', key, 0, false, true, true);
默认情况下,findRecord搜索使用regexp。您应该传递所有6个参数以获得表达式,如
=

或者如果您通过“id”查找,请尝试
store.getById(key)


请看

根据tapped,您知道如何获取索引值吗。