1. #1
    Sencha User
    Join Date
    Feb 2012
    Posts
    11
    Vote Rating
    1
    nocturn is on a distinguished road

      0  

    Default Unanswered: Extraparams and model save

    Unanswered: Extraparams and model save


    Hi
    I was wondering if there is any way to pass an array of objects as extra param of model.save method ?
    For simple types params seem to work.
    Code:
    Ext.define('RightGridModel', {
        extend: 'Ext.data.Model',
        fields: [
            {name: 'id',  type: 'int'},
            {name: 'rightText',   type: 'string'},
            {name: 'digit',type:'int'}
        ]
    });
     var mod = Ext.create('RightGridModel');
                                mod.set('rightText', 'some text');
    mod.save({
                                    url: "Home/Insert",
                                    params: {
                                        par: 'additional parameter'
                                    }
                                });
    However if I want to send and array as an extra param,(of course I changed server side function to be approperiate ) par variable is an empty list. Here is a code I use to send an model and array

    Code:
     mod.save({
                                    url: "Home/Insert",
                                    params: {
                                        par: Ext.encode(array)
                                    }
                                });
    Is there any way to send a model and an array as extra parameter ?? What is the best way to achieve that ?

  2. #2
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    8,872
    Answers
    652
    Vote Rating
    438
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    Sure, just create the array and send it.

    Code:
    var myarray = [];
    myarray.push({ field: value });
    
    rec.save({
      params: {
          mydata: Ext.encode(myarray);
      }
    });
    Regards,
    Scott

  3. #3
    Sencha User
    Join Date
    Feb 2012
    Posts
    11
    Vote Rating
    1
    nocturn is on a distinguished road

      0  

    Default


    Unfortunately it's not working. In the first post I wrote I tried this. To be sure I checked it again, but it still doesnt work
    Edit
    It only works if I send simple types, like int or string. However sending objects in array is not working

  4. #4
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    8,872
    Answers
    652
    Vote Rating
    438
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    Are you having problems on the server side grabbing the data, or are you saying that the data is not sent? Do you inspect the traffic to the server using Firebug/Developer Tools?

    Example:

    Code:
    params: {
        sort: '[{"property":"user_name","direction":"ASC"}]'
    }
    
    function get_json_value($json,$key)
    {
        $result = NULL;
        if(function_exists('json_decode')) {
            $jsonData = json_decode($json, TRUE);
            $result = $jsonData[0][$key];
        }
        return $result;
    }
    
    $sort = (isset($_POST['sort']) ? $_POST['sort'] : $_GET['sort']);
    
    $ord = get_json_value($sort,'property');
    $dir = get_json_value($sort,'direction');
    Regards,
    Scott.

Thread Participants: 1

Tags for this Thread