1. #1
    Ext User
    Join Date
    Nov 2007
    Posts
    23
    Vote Rating
    0
    jonesmc123 is on a distinguished road

      0  

    Question jsonreader not working for me in a Ext.data.Store

    jsonreader not working for me in a Ext.data.Store


    my payload for the proxy is:
    {"totalCount": "1", "records": [{"Agent.First Name": "Nell", "Agent.Annual Salary": "540000.00", "Agent.Last Name": "Carpenter"}]}

    and my store init code:
    Code:
                reader: new Ext.data.JsonReader({
                      root: "records",
                      totalProperty: "totalCount",
                      id: "Agent.First Name",
                      fields: ["Agent.First Name", "Agent.Annual Salary", "Agent.Last Name"]
                  })
    the example for paging looks like:
    {"totalCount":"17467","topics":[{"threadid":"12631","forumid":"5","forumtitle":"Help","title":"Can't load values"}]} //cut off for brevity

    the example's store init code
    Code:
            reader: new Ext.data.JsonReader({
                root: 'topics',
                totalProperty: 'totalCount',
                id: 'threadid',
                fields: [
                    'title', 'forumtitle', 'forumid', 'author',
                    {name: 'replycount', type: 'int'},
                    {name: 'lastpost', mapping: 'lastpost', type: 'date', dateFormat: 'timestamp'},
                    'lastposter', 'excerpt'
                ]
            }),
    the example works but I get "invalid label" on the fetch of the data store.load(...)

  2. #2
    Ext User
    Join Date
    Nov 2007
    Posts
    16
    Vote Rating
    0
    tdondich is on a distinguished road

      0  

    Default


    The root config property specifies which element will contain the array of records. In the example, the root element is topics, which matches up with the example data. Make sure you have an appropriate root config property which matches your JSON data.

  3. #3
    Ext User
    Join Date
    Nov 2007
    Posts
    23
    Vote Rating
    0
    jonesmc123 is on a distinguished road

      0  

    Default I've tried several things for the root and that doesn't fix it

    I've tried several things for the root and that doesn't fix it


    in the example I sent you can see my root is "records" and that's what I have in the jsonreader init code, I tried changing that to something else and that failed with the same error. I also went back and extended my fields definition in case it wasn't enough to put the field names in exactly as they are in the json payload:

    so now my store init looks like:
    Code:
           store = new Ext.data.Store({
                // load using script tags for cross domain, if the data in on the same domain as
                // this page, an HttpProxy would be better
                proxy: new Ext.data.ScriptTagProxy({
                    url: 'http://127.0.0.1:5000/home/get_table_data/'
                }),
                // data: dummyData,
                // reader: reader    
                // create reader that reads the data records
                reader: new Ext.data.JsonReader({
                      root: "records",
                      totalProperty: "totalCount",
                      id: "FirstName",
                      fields: [{name:'FirstName',type:'string'},{name:'Salary',type:'float'},{name:'LastName',type:'string'}]
                  })
            });

    still getting invalid label error. The grid is loaded up on the right element and the paging toolbar is there and I get the loading mask and animation just never loads the data into the grid and I quickly get the invalid label error, I know it's getting to my controller and getting the data back and that data is:
    {"totalCount": "1", "records": [{"FirstName": "Nell", "Salary": "540000.00", "LastName": "Carpenter"}]}

    It's driving me nuts! I know it's probably something very simple and obvious to someone, but I can't see anything missing here

  4. #4
    Sencha - Community Support Team hendricd's Avatar
    Join Date
    Aug 2007
    Location
    Long Island, NY USA
    Posts
    5,963
    Vote Rating
    10
    hendricd will become famous soon enough hendricd will become famous soon enough

      0  

    Default


    Periods ( . ) are not allowed in property names. Convert them to _.
    "be dom-ready..."
    Doug Hendricks

    Maintaining ux: ManagedIFrame, MIF2 (FAQ, Wiki), ux.Media/Flash, AudioEvents, ux.Chart[Fusion,OFC,amChart], ext-basex.js/$JIT, Documentation Site.


    Got Sencha licensing questions? Find out more here.


  5. #5
    Ext User
    Join Date
    Nov 2007
    Posts
    23
    Vote Rating
    0
    jonesmc123 is on a distinguished road

      0  

    Lightbulb got it working finally

    got it working finally


    thank's for the info on period in the field names hendricd, suspected that might be an issue but I had removed those and still wasn't getting the grid to load data and had that invalid label error. What does work for me now is specifying JsonStore explicitly instead of base Store and ScriptTagProxy

    so

    Code:
            jstore = new Ext.data.JsonStore({
                url: '/home/get_table_data/',
                root: 'datarows',
                totalProperty: "totalCount",
                fields: ['FirstName','Salary','LastName']
            });
    works for me. Now to make the fields and columModel built by json data...

    mind you this is using ext.js 2.0 rc1

  6. #6
    Sencha Premium Member
    Join Date
    Nov 2007
    Posts
    79
    Vote Rating
    4
    oldroy is on a distinguished road

      0  

    Default Been looking for this...

    Been looking for this...


    Hello,
    I'm have the same issues. Is there any way that you could post your finished code (store, reader, grid and your working returned json? This seems to be a recurring issue with new users and users going from 1.x to 2.0 as there have been big changes in the grid and there is no actual working gridpanel loaded from returned json example anywhere.

    Also - did you have to dump your naming convention to get this to work? agent.firstname is now agent_firstname or firstname?



    Thanks
    Last edited by oldroy; 5 Dec 2007 at 3:07 PM. Reason: mispellings

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

      0  

    Default


    You can't use periods in the names b/c javascript will try to interpret it as a object property.

  8. #8
    Ext User
    Join Date
    Dec 2007
    Posts
    31
    Vote Rating
    0
    vertigoMX is on a distinguished road

      0  

    Default


    Yes, please post a working sample of all pages.

    thanx

  9. #9
    Sencha User
    Join Date
    Apr 2007
    Location
    Ottawa, Canada
    Posts
    178
    Vote Rating
    1
    ffzhuang will become famous soon enough

      0  

    Default check server side code

    check server side code


    seems your serve side code have problem because of using ScriptTagProxy

    check to see whether your serve side add:

    Code:
            boolean scriptTag = false;
            String cb = request.getParameter("callback");
            if (cb != null) {
                scriptTag = true;
                response.setContentType("text/javascript");
            } else {
                response.setContentType("application/x-json");
            }