Results 1 to 10 of 10

Thread: DataWriter and callback function

  1. #1

    Default DataWriter and callback function

    I was wondering if one can define a callback function when using the new DataWriter, as it is possible when using a DataReader:
    Code:
    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:
    Code:
    store.save({
        callback: function(r,options,success){
            if(!success)
                alert("Unable to save the data.");
        }
    });

  2. #2
    Sencha User
    Join Date
    Apr 2008
    Location
    West Linton, Scotland
    Posts
    244

    Default

    Have a look at the write event for the store
    There is an example on how it is used

  3. #3

    Default

    That does the trick
    Thanks!

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

  4. #4

    Default

    Err, actually, I can't get it working properly:

    Code:
    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
    Code:
    {"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?

  5. #5
    Sencha User
    Join Date
    Apr 2008
    Location
    West Linton, Scotland
    Posts
    244

    Default

    what happens when you set success:true?

  6. #6

    Default

    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

  7. #7

    Default

    So am I correct in saying that your judgment is, "it's just busted, that's all?"

  8. #8

    Default

    try update event instead of write

  9. #9

    Default

    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?

  10. #10

    Default

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •