Get value from the store

I have the following repository:

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'} ] } }); 

And I manage to insert and get a value like this:

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

But it is so cumbersome to get the index first and then get the value, how can you do something like this:

 var value = store.get(key); 

?

+4
source share
2 answers

you can use function

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

this is a shortcut for

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

Greetings, Oleg

+6
source

Use

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

By default, findRecord search uses regexp. You must pass all 6 parameters to get expresstion, for example ===

Or, if you find by "id", try store.getById(key)

See fiddle

0
source

All Articles