1. #1
    Sencha User
    Join Date
    Nov 2011
    Posts
    25
    Vote Rating
    0
    danielleng is on a distinguished road

      0  

    Default 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:

    Code:
    Record.save({
           callback: function(records, operation, success){
                  console.log("Yeaa!");
           }
    });
    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.

    And here is my configured proxy:

    Code:
    proxy: {
            type: 'direct',
            api: {
                     //client-side function : server-side function.
                     update: QueryTraining.updateTraining
            },
            reader:{
                     type:'json',
                     successProperty: 'success'
            }
    }
    Anyone knows whats going on ?

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,330
    Vote Rating
    847
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    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
    ________________
    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 in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Ext JS Premium Member
    Join Date
    Sep 2010
    Posts
    364
    Vote Rating
    6
    stewardsencha is on a distinguished road

      0  

    Default


    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.

    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
                }
            })
    It saves and deletes fine.
    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 ?

  4. #4
    Sencha - Ext JS Dev Team
    Join Date
    Jun 2011
    Location
    San Diego, CA
    Posts
    205
    Vote Rating
    40
    nohuhu has a spectacular aura about nohuhu has a spectacular aura about nohuhu has a spectacular aura about

      0  

    Default


    @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.