-
30 Dec 2011 1:59 AM #1
Callback Function for Model.save()
Callback Function for Model.save()
Hey everyone, I seem to be unable to do callbacks when calling Model.save().
Here is my save function:
I also tried success: function() and it didn't work too. I had my server-side method return a "success" property explicitly set to "true", also to no avail.Code:Record.save({ callback: function(records, operation, success){ console.log("Yeaa!"); } });
And here is my configured proxy:
Anyone knows whats going on ?Code:proxy: { type: 'direct', api: { //client-side function : server-side function. update: QueryTraining.updateTraining }, reader:{ type:'json', successProperty: 'success' } }
-
30 Dec 2011 8:17 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,710
- Vote Rating
- 436
The success property should have no affect on success/failure. That should run off of the http status code (eg 200 or 500)
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
24 Feb 2013 11:10 AM #3
Sorry but I do not understand the answer.
Server is returning 200, I need to let the user know the record was saved.
No callbacks seem to get fired.
It saves and deletes fine.Code:*** EXTDIRECT Ext.app.REMOTING_API = { ... "VFave":[ {"name":"Create","len":2}, {"name":"Delete","len":1}, {"name":"extCrud","len":1} ], ... *** MY MODEL Ext.define('MBH.model.VFave', { extend: 'Ext.data.Model', IdProperty:'id', fields:[ ... ], proxy: { type: 'direct', reader: { type: 'json', root: 'data' }, api:{ create:function(rec,callback,directProxy){ Ext.app.VFave.Create(rec,callback,directProxy) }, destroy:function(rec,callback,directProxy){ Ext.app.VFave.Delete(rec,callback,directProxy) }, update:function(rec,callback,directProxy){ debugger Ext.app.VFave.extCrud('delete', rec,callback,directProxy) } }, ... *** MY CONTROLLER var vf = this.getFaveModel() vf.set('video_id',111) vf.set('user_id',222) vf.save({ success: function(record, operation) { //record is the updated record, except for collections //this collection will have the full records: //operation.resultSet.records //operation.resultSet.records[i] for each one if you are batching debugger }, failure: function(record, operation) { //handle failure(s) here debugger } })
But I dunno how to let the user know it happened.
You can see I have cobbled together from examples and don't quite get it yet.
How do I get a success or failure callback from a model save call using ExtDirect proxy ?
-
8 Mar 2013 5:04 PM #4
@stewardsencha Not sure what is the problem here. You're calling model.save() but do not pass it the callback function. That method accept the same config options as Ext.data.Operation constructor, and neither "success" nor "failure" are among them. You can take a look at Ext.data.Model.save source, it's not very complicated.
Also, it's not necessary to configure your proxy with function references. String method names will work too, and actual Direct method references will be resolved at proxy construction time (4.1) or at first Direct method call (4.2).
Regards,
Alex.


Reply With Quote