PDA

View Full Version : data.store update



phyton
24 Apr 2010, 3:56 PM
hi all

store.update() How do I add this code?

store.on('load', function(){

for ( var i in store.reader.jsonData['results'] )
{

if(store.reader.jsonData['results'][i]['reach'] > 2)
{
//how to update store.reader.jsonData['results'][i]['reach'] = store.reader.jsonData['results'][i]['reach'] - 1 ?
}

}

store.save();
grid.getView().refresh();

});

Nesta
25 Apr 2010, 3:58 AM
The load event of the store, gets the store and the new records as parameters



store.on("load", function(store, records){
for(var i=0; i<records.length;i++){
if(record[i].data.reach>2)
store.getById(records[i].data.id).data.reach = (record[i].data.reach-1)
}
};


Changing the reach property in this way, will not send a update event to the server. do you really have to change
the server data on clientside?

phyton
25 Apr 2010, 9:28 AM
yes, I will just change the client side.
onload function to store "store, records" I have added to their argument, but "records" is undefined in function

Nesta
25 Apr 2010, 9:35 AM
hm i pasted the code into my app and it seams to work. expect the typo in the above code (record -> records +s)

extjs api :


records : Ext.data.Record[]The Records that were loaded

is there any data in the store? just make a for(var i=0; i<store.getCount();i++) and update the data.

phyton
25 Apr 2010, 10:10 AM
yes there is data in the store

Nesta
25 Apr 2010, 9:36 PM
than this should work


store.on("load", function(store){
for(var i=0; i<store.getCount()i++){
if(store.getAt(i).data.reach>2)
store.getAt(i).data.reach = (store.getAt(i).data.reach-1)
}
};

phyton
26 Apr 2010, 3:54 AM
Thank you very much. it worked.