2012-07-29 127 views
4

值我有以下的店铺:检索存储

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); 

回答

6

你可以使用函数

var record = store.findRecord('id', key) 

它是一个快捷方式到

index = store.find('id', key); 
record = index != -1 ? store.getAt(index) : null; 

干杯,奥列格

+0

感谢,认为解决它 – 2012-07-30 08:58:22

+0

你有什么想法如何获得索引值根据tapped.http://stackoverflow.com/questions/18206412/getting-index-value-0-from-dataview-any-list-itemtap-from-sencha-touch – 2013-08-14 07:28:30

0

使用

store.findRecord('id', key, 0, false, true, true); 

默认情况下,findRecord搜索使用正则表达式。你应该通过所有6个参数,以获得expresstion像===

或者,如果你所说的“ID”找到尝试store.getById(key)

fiddle