Hybrid View

  1. #1
    Sencha User Lobos's Avatar
    Join Date
    Oct 2007
    Location
    Sao Paulo, Brazil
    Posts
    461
    Vote Rating
    -1
    Lobos is an unknown quantity at this point

      0  

    Default [SOLVED]serialize object

    [SOLVED]serialize object


    HI there,

    I have a store and I would like to serialize the data for export, is there such a function as this for the store? I know I can do something like this:

    store.data.each(function() {
    //do something with this.data
    });

    but I was wondering if there was something like

    Ext.serialize(store.data);

    That would put the object as JSON into a string for export...

    here is some info on this so I might just try one of these solutions (if there is nothing in Extjs that can)

    crockford's stringify:
    http://www.json.org/json2.js

    and something else here
    http://blog.stchur.com/2007/04/06/se...in-javascript/

    -Lobos

  2. #2
    Sencha User Lobos's Avatar
    Join Date
    Oct 2007
    Location
    Sao Paulo, Brazil
    Posts
    461
    Vote Rating
    -1
    Lobos is an unknown quantity at this point

      0  

    Default


    I ended up using this function from:

    http://blog.stchur.com/2007/04/06/se...in-javascript/

    PHP Code:
    function serialize(_obj)
    {
       
    // Let Gecko browsers do this the easy way
       
    if (typeof _obj.toSource !== 'undefined' && typeof _obj.callee === 'undefined')
       {
          return 
    _obj.toSource();
       }

       
    // Other browsers must do it the hard way
       
    switch (typeof _obj)
       {
          
    // numbers, booleans, and functions are trivial:
          // just return the object itself since its default .toString()
          // gives us exactly what we want
          
    case 'number':
          case 
    'boolean':
          case 
    'function':
             return 
    _obj;
             break;

          
    // for JSON format, strings need to be wrapped in double-quotes
          
    case 'string':
             return 
    '\'' _obj '\'';
             break;

          case 
    'object':
             var 
    str;
             if (
    _obj.constructor === Array || typeof _obj.callee !== 'undefined')
             {
                
    str '[';
                var 
    ilen _obj.length;
                for (
    0len-1i++) { str += serialize(_obj[i]) + ','; }
                
    str += serialize(_obj[i]) + ']';
             }
             else
             {
                
    str '{';
                var 
    key;
                for (
    key in _obj) { str += key ':' serialize(_obj[key]) + ','; }
                
    str str.replace(/\,$/, '') + '}';
             }
             return 
    str;
             break;

          default:
             return 
    'UNKNOWN';
             break;
       }

    I still needed to use the each a little bit... but the string is ready to be exported and decoded on the server side.

    PHP Code:
    var count 0;
    store.data.each(function() {
        
    expData[count++] = this.data;
    });
                            
    alert(serialize(expData)); 

  3. #3
    Sencha - Architect Dev Team aconran's Avatar
    Join Date
    Mar 2007
    Posts
    9,413
    Vote Rating
    129
    aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold

      0  

    Default


    Try Ext.encode(myData)
    Aaron Conran
    @aconran
    Sencha Architect Development Team

  4. #4
    Sencha User Lobos's Avatar
    Join Date
    Oct 2007
    Location
    Sao Paulo, Brazil
    Posts
    461
    Vote Rating
    -1
    Lobos is an unknown quantity at this point

      0  

    Default


    LOL yep that's it... hahahahha I did try this, but before I did the each() so I was getting the "too much recursion error", but now it's working perfectly sooo, now it;s just this:

    var count = 0;
    store.data.each(function() {
    expData[count++] = this.data;
    });

    alert(Ext.encode(expData));

    that's better thanks for the advice!

    -Lobos

  5. #5
    Sencha User
    Join Date
    Dec 2010
    Posts
    5
    Vote Rating
    0
    hmezamx is on a distinguished road

      0  

    Default Serializing a grid columns model

    Serializing a grid columns model


    I need to serialize the grid's column model. The premise is that I need to be able to store the grid configuration to the database for reuse and I'm trying to accomplish this by serializing the column model and consume it back.

    I forgot to mention that I tried stringifying the object but the column model apparently has circular structures

    is this possible or is there a better approach.


    ~Thanks

  6. #6
    Sencha User
    Join Date
    Nov 2010
    Posts
    47
    Vote Rating
    0
    anshu_gupta is on a distinguished road

      0  

    Default


    I have a gridpanel. It has a checkbox colums model. i want to select the rows through checkboxes and send those records to server.
    I get the data in Firebug but i get a too much recursion error. I am using getSelections() method. i want to know how can i get the id's of the all the elements in the array and post to server. Ext.encode() is not working.