1. #1
    Ext User
    Join Date
    Jun 2009
    Posts
    6
    Vote Rating
    0
    mainmanmauricio is on a distinguished road

      0  

    Default Bug in Ext.data.JsonReader?

    Bug in Ext.data.JsonReader?


    Hi,

    I am new to Ext-js and I encountered a peculiarity that just might be a bug.

    In my Extjs 3.0 RC2 based program, using an Ext.data.ArrayReader to fill a grid works
    while using an Ext.data.JsonReader to do the same job gives me
    a grid containing only blank lines.

    It seems that this is not by chance. Ext.data.ArrayReader is derived from Ext.data.JsonReader and
    the only difference is the implementation of the readRecords method.

    Closer inspection leads me to suspect the following method in Ext.data.JsonReader.

    // private extractValues
    extractValues: function(data, items, len) {
    var f, values = {};
    for(var j = 0; j < len; j++){
    f = items[j];
    var v = this.ef[j](data); // v is always undefined
    values[f.name] = f.convert((v !== undefined) ? v : f.defaultValue, data);
    }
    return values;
    },

    The values extracted are from the json data object are always undefined. Probably because
    they are extracted by name instead of being extracted by position.

    I am doing something foolish or is this a bug?

    Thanks.

    Kind regards,
    Maurice

  2. #2
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,508
    Vote Rating
    56
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    They are different classes. Using them to do the same job is wrong.

  3. #3
    Ext User
    Join Date
    Jun 2009
    Posts
    6
    Vote Rating
    0
    mainmanmauricio is on a distinguished road

      0  

    Default


    Quote Originally Posted by Animal View Post
    They are different classes. Using them to do the same job is wrong.
    Sure, the point I was trying to make is that I expected a JsonReader to work to read the JSON
    encoded data (which I am returning from the webserver).

    But for some reason, the JsonReader does not work but the ArrayReader does.
    I guest it is just me.

    Kind regards,
    Maurice

  4. #4
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,508
    Vote Rating
    56
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    If you return an Array as each data row object, it will need an ArrayReader

  5. #5
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,508
    Vote Rating
    56
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    I have proposed a merger whereby JsonReader and ArrayReader become one, and it just uses either numeric indices or string property names: http://extjs.com/forum/showthread.php?t=69453

    But no response from the dev team.

  6. #6
    Ext User
    Join Date
    Jun 2009
    Posts
    6
    Vote Rating
    0
    mainmanmauricio is on a distinguished road

      0  

    Default


    Quote Originally Posted by Animal View Post
    They are different classes. Using them to do the same job is wrong.
    Quote Originally Posted by Animal View Post
    I have proposed a merger whereby JsonReader and ArrayReader become one, and it just uses either numeric indices or string property names: http://extjs.com/forum/showthread.php?t=69453

    But no response from the dev team.
    Thanks!

    I can't imagine why it would be deemed appropriate for a JsonReader class to not properly deal with JSON encoded data.

    But then again I do not know Javascript very well and maybe arrays are not objects in Javascript.

    Anyway if the JsonReader were to have properly dealt with arrays it would have saved me quite a bit of debugging.

    Kind regards,
    Maurice

  7. #7
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,508
    Vote Rating
    56
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    JsonReader reads an object.

    It's not JSON once it gets into the browser.

    JSON is what is on thw wire.

    JSON is a string representation of data.

    You are confused here.

  8. #8
    Sencha User
    Join Date
    Jun 2012
    Posts
    4
    Vote Rating
    0
    mjrobin is on a distinguished road

      0  

    Default extjs 4 - Ext.data.Record.create

    extjs 4 - Ext.data.Record.create


    Im getting the following error on a getForm().submit. My objective is to search on multiple fields and return json stringto store to a grid



    TypeError: l.fields is undefined
    [IMG]file:///C:\Users\mark\AppData\Local\Temp\msohtmlclip1\01\clip_image001.gif[/IMG] ...else{l=b._lastItemForPoint;if(l){b.fireEvent("itemmouseout",l);delete b._lastIte...

    My json


    success true
    results 1
    rows [Object { client_id=
    "1"
    , clientdate=
    "2012-09-15"
    , trn=
    "1234567"
    , more...}, Object { client_id=
    "2"
    , clientdate=
    "1972-09-15"
    , trn=
    "78899"
    , more...}]
    0 Object { client_id=
    "1"
    , clientdate=
    "2012-09-15"
    , trn=
    "1234567"
    , more...}
    client_id "1"
    clientdate "2012-09-15"
    trn "1234567"
    lname "name"
    fname "My"
    1 Object { client_id=
    "2"
    , clientdate=
    "1972-09-15"
    , trn=
    "78899"
    , more...}
    client_id "2"
    clientdate "1972-09-15"
    trn "78899"
    lname "brown"
    fname "yanique"


    Code giving error:


    function success_handler(frm, action){
    //alert(Ext.encode(action.result));
    //var jSource=(Ext.encode(action.result));

    var Record = Ext.data.Record.create([ 'trn','firstname','lname' // map the Record's "job" field to the row object's "occupation" key
    ]);

    var myReader = new Ext.data.JsonReader(
    {
    totalProperty: "results",
    root: "rows",
    idProperty: "client_id"
    },
    Record
    );


    var store = new Ext.data.Store({reader: myReader});
    // store.loadData(Ext.util.JSON.decode(jSource));
    console.log(store);

    Any insight will be appreciated

Thread Participants: 2