2012-07-29 108 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