Extjs copy from one store records to a new model.

Today i had some problems in copy records from one store to compare to a new model, the new model had new records and the old records had garbage, in this case i had to trim the garbage and pass only the values in to the new data model.

loadRecords: function (records) {
var thisGrid = this.getView().down('gridpanel'),
store = thisGrid.getStore();
len = records.length, i = 0, temp = [];

for (; i < len; i++) {
var rec = Ext.create('app.model.something');

for (x in records[i].data) {
if (temp[i].data.hasOwnProperty(x)) {
temp[i].data[x] = records[i].data[x];

The above is my function to load the records from other grid store, what i did was:

create an array temp and in each for loop i create a new data model, then i went to pick each one of them and compare if the array temp had that property and if yes then i copy only the value from the old record to the new one, in the end i load them at once in the store.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s