PDA

View Full Version : Getting a reference to a store



mbritton
23 Jan 2012, 11:44 AM
I've defined a model and a store. How would I get a reference to the store? The below attempts are failing:

// Uncaught TypeError: Object #<Object> has no method 'getStore'
var store = Ext.getStore('storyStore');

// Uncaught TypeError: Cannot read property 'StoreMgr' of undefined
var store = Ext.data.StoreMgr.getStore('storyStore');

My code:



Ext.define('model.Story', {
extend: 'Ext.data.Model',
autoLoad:true,
fields: [
{name:'entry_title',type:'string'},
{name:'entry_text',type:'string'},
],
proxy: {
type: 'ajax',
url: '<DELETED>',
reader: {
type: 'json',
root: 'sample'
}
}
});


Ext.define('StoryStore', {
extend: 'Ext.data.Store',
requires: 'model.Story',
model: 'model.Story',
autoLoad:false,
storeId:'storyStore',
proxy: {
type: 'ajax',
url: '<DELETED>',
reader: {
type: 'json',
root: 'sample'
}
}
});


Thanks in advance!

friend
23 Jan 2012, 12:24 PM
Visit the example in the Ext.data.StoreManager (http://docs.sencha.com/ext-js/4-0/#%21/api/Ext.data.StoreManager) API Documentation.

jay@moduscreate.com
23 Jan 2012, 12:34 PM
try Ext.StoreManager.get('myStoreId')

mbritton
23 Jan 2012, 1:51 PM
When I create my application and try to set its stores and models Arrays, Ext looks for the files in app/stores etc etc, directories that don't exist. How do I override this behavior?

lorezyra
23 Jan 2012, 4:30 PM
If you just want to reference the store, then do this:



var store = Ext.StoreMgr.lookup('storyStore');


You should only use getStore() when referencing it via a grid... ex)


var myGrid = this.up('grid');
var myGridStore = myGrid.getStore(); //...

mbritton
24 Jan 2012, 11:13 AM
Ah, that was my mistake. Thanks for your help!