PDA

View Full Version : DataWriter and callback function



Thomas Triplet
21 Aug 2009, 7:29 AM
I was wondering if one can define a callback function when using the new DataWriter, as it is possible when using a DataReader:

store.load({
params:{start:0, limit:30},
callback: function(r,options,success){
if(!success)
alert("Unable to load data.");
}
});

Is it possible to do something like:

store.save({
callback: function(r,options,success){
if(!success)
alert("Unable to save the data.");
}
});

andycramb
22 Aug 2009, 11:01 AM
Have a look at the write event for the store
There is an example (http://extjs.com/deploy/dev/examples/writer/writer.html)on how it is used

Thomas Triplet
24 Aug 2009, 7:25 AM
That does the trick
Thanks!

It's a lit bit confusing/weird that the writer and reader have different models for the callback function

Thomas Triplet
24 Aug 2009, 8:17 AM
Err, actually, I can't get it working properly:



store = new Ext.data.GroupingStore( {
storeId :'storeId',
remoteGroup :true,
reader :new Ext.data.JsonReader( {
root :'results',
idProperty :'id',
totalProperty :'number_records'
}, MyRecord),
writer :new Ext.data.JsonWriter( {
//writeAllFields: true,
encode : true
}, Passport.SupernatantPlateWell),
proxy :new Ext.data.HttpProxy( {
api: {
read :'php/jser/jsoner_plate_screening.php',
create: 'php/saver_plate_screening.php',
update: 'php/saver_plate_screening.php',
destroy: 'php/saver_plate_screening.php'
}
}),
listeners: {
write : function(store, action, result, res, rs) {
alert('write listener');
},
exception : function(proxy, type, action, options, res, arg) {
alert('write listener');
}
}
});

PHP backend returns
{"success":false,"message":"error trial","data":""}

However, I never go in the write listener, always the exception listener. Parameters are always the same:

type=response
action=update
others=null or empty


Any suggestion?

andycramb
24 Aug 2009, 1:27 PM
what happens when you set success:true?

Thomas Triplet
24 Aug 2009, 2:53 PM
Exactly the same (I also checked successProperty). Also tried playing with HTTP status, but still the same. I guess I'll do it the old fashioned way, by creating the AJAX request (as I used to do before DataWriters were introduced)
Thanks anyways

Mike Robinson
29 Aug 2009, 6:33 AM
So am I correct in saying that your judgment is, "it's just busted, that's all?"

Nagadev
29 Aug 2009, 11:42 AM
try update event instead of write

Mike Robinson
29 Aug 2009, 11:56 AM
Go to the source-code of "Ext.data.store" and search for the string "hasUniqueUrl." Also review the function "save()." This appears to be the logic that's actually making the determination of what to do and what events to fire.

Did you set "successproperty?" Is the HTTP code 200?

jergarmar
3 Nov 2009, 1:57 PM
I'm pretty sure the reason you had problem with this is because the listener needs to be on the PROXY. I'm ran into the same problem and solved it that way.