I would like to have different instances of the same view with different stores at the same time in an ExtJS application. At the moment i ceate multiple instances of the same view (Ext.view.View) in the viewport.
But what is the best practice to have a different store in every view? Every example that i found uses a Store-ID in the view that was created using the stores-Config of the controller. But this would use the same store for every view.
At the moment i figured the following possible solutions:
Is any of this solutions the best practice or should it be done differently?
The thing with the stores array of the controller
is, that it will override any storeId
defined. After loading the store class the controller set the storeId
by a namespace convention, create the store and create the getter method method by using the value as the soreId
.
Let me introduce option 4
requires
array). itemId
of the view (set it when creating the view!).initComponent
create the storeId
and lookup the store in the StoreManager. If it not exist create it and supply a Customer config and the storeId
. If you need to destroy the view and the store each time take a look at this post
Demo initComponent
initComponent: function() {
var me = this,
storeId = me.storeId + me.itemId;
me.store = Ext.StoreManager.lookup(storeId);
if(me.store === null)
me.store = Ext.create('App.data.CustomViewStore',Ext.apply({storeId: storeId},me.storeCfg || {}));
me.callParent(arguments);
}
Note: If you load the view with the views
array you will end up with a getter that may not give you the view you expected. You may use the requires array of the controller here, too. If you want to use getter simply create your own one by using the refs config.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With