-
25 Jul 2010 11:24 AM #1
Help changing Json Store data
Help changing Json Store data
I have two JsonStores.
One is a full list of data, and the other is just the updates of the data(if any). If there is a match of the ids i should change the data of that row in one store with the data from the other.
Is this a correct way to compare the 2 stores. Also, how do i change the values of liveScoreStore with the data of updateScoreStoreCode:updateScoreStore.each(function(upd){ liveScoreStore.each(function(liv){ if (upd.data['id'] == liv.data['id']){ console.log("WE HAVE A MATCH!"); //liv.data['currentScore'] == upd.data['currentScore']; } }); });
-
25 Jul 2010 12:05 PM #2
A solution could be :
Code:updateScoreStore.each(function(upd){ if(liveScoreStore.find('id', upd.get('id'), 0, false, true) == (-1)) liveScoreStore.loadData(upd.data, true); });
-
25 Jul 2010 9:28 PM #3Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 41
If you also configured the id as the idProperty of the store reader then using store.indexOfId is much faster than a tablescan.
-
28 Jul 2010 9:09 AM #4
Condor, do you mean something like this?
And thenCode:var XMLReader = new Ext.data.XmlReader ({ record: 'Match', idProperty: 'Match@id' },[ {name: 'mid', mapping: '@id'}, {name: 'startTime', mapping: '@startTime'}, {name: 'statusType', mapping: '@statustype'}, {name: 'status', mapping: '@status'}, {name: 'home', mapping: 'Home@name'}, {name: 'homeStanding', mapping: 'Home@standing'}, {name: 'away', mapping: 'Away@name'}, {name: 'awayStanding', mapping: 'Away@standing'}, {name: 'country', mapping: 'Information > country'}, {name: 'league', mapping: 'Information > league'}, {name: 'currentScore', mapping: 'Results > Result@value'} ]);
ThanksCode:updateScoreStore.each(function(upd){ if(liveScoreStore.indexOf(upd.get['mid'])) //change liveScoreStore row data });
Nicos
-
28 Jul 2010 11:15 AM #5Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 41
Almost.
1. The idProperty should be '@id'.
2. The loop should contain liveScoreStore.indexOf(upd.id)
-
28 Jul 2010 11:54 PM #6
Thank you Condor! Works great.
Since we are on the subject, how to change the liveScoreStore with the date from the updateStore, so the changes will be visible on the grid?
They share the same reader, and the data is exactly the same.
This fails to workCode:liveScoreStore = new Ext.data.GroupingStore({ url: "update/soccerLive.xml", autoDestroy : true, reader: XMLReader, sortInfo:{field: 'mid', direction: "ASC"}, groupField:'status' }); updateScoreStore = new Ext.data.GroupingStore({ url: "update/soccerUpdate.xml", reader: XMLReader, sortInfo:{field: 'mid', direction: "ASC"}, groupField:'status' });
How can i do it correctly?Code:function processUpdate(){ console.log("In processUpdate. " + updateScoreStore.getCount()); var grid = Ext.getCmp('liveScores'); updateScoreStore.each(function(upd){ if (liveScoreStore.indexOf(upd.id)) { console.log("Match: " + upd.id + "(" + upd.get("home") + " Vs " + upd.get("away") + ")"); var myRecord = grid.getStore().getById(upd.id); myRecord.set('currentScore', upd.get('currentScore')); grid.getStore().commitChanges(); } else { console.log("Adding row...") //liveScoreStore.add(upd.record); } }); }
Regards,
Nicos
-
29 Jul 2010 1:20 AM #7Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 41
Code:function processUpdate(){ var liveScoreStore = Ext.getCmp('liveScores').getStore(); updateScoreStore.each(function(rec){ var rec2 = liveScoreStore.getById(rec.id); if (rec2) { rec2.set('currentScore', rec.get('currentScore')); rec2.commit(); } else { liveScoreStore.add(rec.copy()); } }); }
-
29 Jul 2010 2:56 AM #8
Similar Threads
-
JSON Store isn't loading JSON Data
By WhirlingDerBing in forum Ext 3.x: Help & DiscussionReplies: 3Last Post: 3 Nov 2009, 4:37 PM -
Second json store is created under each returned json Store.data.item
By daddyschmack in forum Ext 2.x: Help & DiscussionReplies: 1Last Post: 19 Aug 2009, 4:34 AM -
Grid doesn't refresh it's content, after changing data in it's store
By Surgeon in forum Ext 2.x: Help & DiscussionReplies: 8Last Post: 4 Dec 2008, 11:44 AM -
Dynamically Changing url of Data Store
By fangzhouxing in forum Ext 2.x: Help & DiscussionReplies: 2Last Post: 17 Jul 2008, 10:49 PM -
Dynamic changing JSON store root
By sistasi in forum Ext 2.x: Help & DiscussionReplies: 1Last Post: 9 Apr 2008, 2:49 AM


Reply With Quote