PDA

View Full Version : Copy, Duplicate or Clone Store (ExtJs 4)



jweymarn
13 Dec 2011, 1:17 AM
Hey!

I have a store from a json file that i want copied. How is this done!?

Some help is available for this but I am not able to do it with ExtJS 4.


var newStore= new Ext.data.Store({
model : oldStoreModel
});
oldStore.each(function (r){
records.push (r.copy());
});
newStore.loadRecords(records);

In the above the newStore is empty...

tobiu
13 Dec 2011, 2:15 AM
well, a store definitely should get more configs than just a model definition and you should not pass that one in via reference.

i would go the mvc way: create a custom class for your model using Ext.define(). Create a class for you store as well using the model. Create a new instance (using Ext.create() instead of new) of the store, then you can load the data from the first store.

tip:
http://docs.sencha.com/ext-js/4-0/#!/guide/application_architecture
-> Creating a Model and a Store

jweymarn
13 Dec 2011, 2:33 AM
Hehehe... Not so simple I see...

I need this in order to show only part of the records of a store in a graph. I´ll just go with plan B and generate an optimized json for the graph...

Nevertheless, thank you for your reply.

tobiu
13 Dec 2011, 2:45 AM
you can also filter the store ->

store.filter()
store.filterBy()

the approach to create reuseable components is not difficult to implement.