View Full Version : Dynamically change Ext.List store

7 Sep 2012, 11:02 AM
Disclaimer: I'm very new to Sencha Touch and just developing an application piece-by-piece as I'm learning the product. I have an 'Ext.List' working so that when I tap an item in the list it activates the next card (in a TabPanel), but I want the data shown in the next card to vary depending on which list item was tapped. I know which item was clicked, but what I'm having trouble with is setting the data store for the list.

basically, I'm thinking something like this in the itemTap function specified in my controller:

if (idx==0) {
} else if (idx==1) {

But how do I get a reference to the stores? I've tried the class name 'MyApp.store.MyStore1' but that's not working. Looks like setStore wants an actual object, but I can't figure out how to get it?

Does Sencha Touch not instantiate the classes declared in my applications "stores" array?
I don't think I should create an instance every time there's an itemtap. That doesn't sound efficient.


(Alternatively, and eventually, when my data is coming from a database, I would prefer to just alter the URL on my proxy based on the item tapped. But I thought it'd be easier to start with a separate store for each category and get things working, then change my stores to proxies with specific URLs, and eventually maybe a single store and change the proxy URL to specify certain criteria for the retrieval.)

10 Sep 2012, 5:00 AM
It does instantiate all stores in the stores array. It either using the storeId if that config is present in your store or creates a storeId based on the class name and saves it in Ext.data.StoreManager. So all you have to do is pass in a string in setStore that matches the storeId

10 Sep 2012, 6:00 AM

I was getting "The specified store cannot be found" because I typo'd the store name. :">
Then rather than looking for the obvious, I checked the API docs and they say that setStore requires an object, rather than a simple string name of the store.

Also, I was using the full .. "MyApp.store.Storename" name and that didn't work either. Turns out setStore just wants the simple name listed in the stores array.


10 Sep 2012, 6:32 AM
Ext.dataview.DataView (the superclass of Ext.dataview.List), the applyStore method does a Ext.data.StoreManager.lookup on what you pass it. The Ext.data.StoreManager.lookup checks if what is passed to it is a string, if so then does a lookup for that store id. If it's not a string it then checks if it's an instanceof Ext.data.Store. If it is then return it, if not then it will attempt to create an Ext.data.Store.

So you can in fact pass in a string as long as it's a valid store id. You can check the valid store ids to see if there is one in there via Ext.data.StoreManager.keys. That is an array of strings, case is important also.