5
votes

I am working on extjs 4 MVC application.

Application runs the Viewport, which contains tabpanel. Each tab has own controller and multiple views.

See my sandboxs at http://wap7.ru/folio/ext-reuseable-store/TE.html

I have one Store used several times (e.g. one tab in topmenu combobox, another in the clietns grid.) Store configured with autoload: true. Proxy is configured in the Model.

My problem: Store is loaded multiple times - at every mention in the controller [stores] array.

If I remove one from the array [stores] controller- combobox will be empty, although it states store: Ext.getStore ('STORE-ID')

Please give me a hint, or an example of re-using Store (not Model) as in here http://docs.sencha.com/ext-js/4-0/#!/guide/mvc_pt2

3
Posting your code will help us to diagnose this a lot easier.Daniel Attfield
@Lev, do you have the solution? I currently trapped in to this issue, the answer below somehow related to store loading, but I suspect this issue regarding model association and multiple stores. Displaying master data is not straight forward unless I need to have store independent from the object graph and call filter manually in the controller.CallMeLaNN
not really. hoping you will post comment with fix some day here.Lev Savranskiy

3 Answers

1
votes

You can just instantiate your store and load it, remove the autoload.

var store = Ext.create('App.store.YourStore').load();

Then pass that store to all your components, just like you would do when you want a paging bar connected to a grid.

0
votes

This normally works fine to call your store from other controllers:

Ext.getStore('PlatformClient');

I've never tried to put the same store in more than one controller stores array. That seems strange to me.

There are a couple of other oddities about the code you have posted though, maybe they're just typos and maybe they don't make any difference to the framework but they're different from what I normally do so I'll point them out:

First, your model array in the "typical controller" contains a store:

models:[
'te.store.PlatformClient'

],

That one is probably just a typo.

Second, I don't put the full namespace in my store arrays, this is something that may not make a difference, but I don't know. Maybe ExtJS is prepending the namespace on top of the namespace you have written out so it thinks that you are instantiating a different store whenever it initializes a new controller - thereby causing it reload. For example this is more "normal" for whatever it's worth:

stores:[
    'Taxonomy',
    'PlatformClient',
    'DataType'
],
controllers:[
    'Taxonomies' ,
    'DataType' ,
    'DataSale' ,
    'Clients' 
],

Try setting it up like that and get rid of the duplicative stores in the other controller store arrays.

Also, I want to make sure that you caught the bit in the docs about not needing to define a storeId config for MVC stores. The framework will automatically give the store this:

storeId: [StoreClassName] 

So in your example, you would get this automatically:

storeId: 'PlatformClient'

Someone else had trouble with MVC stores recently and it traced back to the framework being flabbergasted by the audacity of the dev supplying their own storeId config with the MVC pattern.

0
votes

We used to have similar problems with loading. Also got issues with filtering in case of multiple use of the same store (you may want to set filter on one but not on the other). Therefore we load all the stores at application launch. Then whenever we need that store for displaying purposes then instead of using the original we are cloning it in the memory with ha utility function as below.

/**
* Use this for example if you want to apply a filter on a store
* but you dont want the original store to change, so:
* singleton store has no filter
* you clone it to be used with filters in some places.
*
* Note: this will have memory proxy, so no changes to the stores are persistent,
* changes will have no effect on the local/remote db.
*
*/
createStore: function(storeId, data) {

    //
    // Creates a new store from the given array of records without
    // registering the new store.
    // See cloneStore for more info
    //
    var modelName = storeId;
    var prevStore = Ext.getStore(storeId);
    data = data || prevStore.data.all;

    var clonedStore = Ext.create('App.store.' + storeId, {
        data: data,
        model: 'App.model.' + modelName,
        proxy: 'memory'
    });

    Ext.data.StoreManager.register( prevStore );

    return clonedStore;

}

Please note the cloned copy is using memory proxy. Therefore write operations shouldn't be done on it. If you need to update the store then always use the original.

I hope this helps on some way.