1. #1
    Ext User
    Join Date
    Jan 2008
    Posts
    7
    Vote Rating
    0
    molasses is on a distinguished road

      0  

    Default [2.0][CLOSED] Creating a JsonStore destroys existing JsonReader.recordType property

    [2.0][CLOSED] Creating a JsonStore destroys existing JsonReader.recordType property


    Description
    1. Create a new Record
    2. Create a JsonReader that uses the Record
    3. Create a JsonStore that uses the JsonReader
    4. The JsonStore has now created a new JsonReader and wiped out the recordType property. So if you call JsonStore.load() it will give you the exception "Record has no properties"
    Example

    Code:
    var Employee = Ext.data.Record.create([
    {name: 'name', mapping: 'name'},
    {name: 'occupation'}
    ]);
    
    var myReader = new Ext.data.JsonReader({
    totalProperty: "results",
    root: "rows",
    id: "id"
    }, Employee);
    
    var store = new Ext.data.JsonStore({
    url: 'test',
    reader: myReader
    });
    
    store.load();
    The problem exists on line 44 of JsonStore.js

    Code:
    reader: new Ext.data.JsonReader(c, c.fields)
    Firstly, I don't think it needs to create a new JsonReader when there already is one specified. It should just check for c.reader.

    And secondly, it only passes c.fields. So you lose the c.reader.recordType when it creates the new JsonReader.


    Temporary workaround

    After creating the JsonStore and before calling store.load(), simply set the reader property back to your original reader.

    Code:
    store.reader = myReader;

  2. #2
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    94
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    I think it is more a matter of documentation of JsonStore.

    JsonStore should not have config options proxy and reader, but it should have config options for the JsonReader (id, root, successProperty and TotalProperty)

    ps. This problem can be easily worked around by using a Store instead of a JsonStore.

  3. #3
    Sencha User thejoker101's Avatar
    Join Date
    Mar 2007
    Posts
    349
    Vote Rating
    0
    thejoker101 is on a distinguished road

      0  

    Default


    JsonStore is supposed to be used as an all-in-one store config.

    Code:
    var store = new Ext.data.JsonStore({
    url: 'test',
    totalProperty: "results",
    root: "rows",
    id: "id",
    fields: [
        {name: 'name', mapping: 'name'},
        {name: 'occupation'}
    ]
    });
    
    store.load();

  4. #4
    Ext User
    Join Date
    Jan 2008
    Posts
    7
    Vote Rating
    0
    molasses is on a distinguished road

      0  

    Default


    Thanks for the info. I am still pretty new to Ext JS.

    Do you want me to open a new bug report for the API documentation?
    In the API docs for JsonStore it does list 'reader' in the config options.

    I think it would make more sense if JsonStore just accepted the 'reader' field on creation though. Seems like that would be more intuitive.

  5. #5
    Sencha User
    Join Date
    Mar 2007
    Posts
    7,854
    Vote Rating
    4
    tryanDLS is on a distinguished road

      0  

    Default


    You can update the existing sticky bug thread for doc. JsonStore was specifically built as a simple way to build the store without having to create a Reader. If you need that functionality, you should be using a regular Store with Reader.