Results 1 to 5 of 5

Thread: Ext.data.Store reader root, json problem

  1. #1

    Question Ext.data.Store reader root, json problem

    Hi,
    I have a problem with the "Ext.data.Store reader" when I try to read a json...

    my json:
    Code:
    {
        "result": {
            "date": "10/01/2012",
            "elem": [
                {
                    "name": "Name 1",
                    "prize": "Ipad2"
                },
                {
                    "name": "Name 2",
                    "prize": "PlayStation3"
                },
                {
                    "name": "Name 3",
                    "prize": "GalaxyS2"
                },
                {
                    "name": "Name 4",
                    "prize": "GalaxyS2"
                },
                {
                    "name": "Name 5,
                    "prize": "BlueRay"
                }
            ],
            "status": true
        }
    }
    my js code parser:
    Code:
        Ext.regModel('response', {
            fields: [{
                name: 'date', 
                type: 'string'
            },
            {
                name: 'name', 
                type: 'string'
            },
    
            {
                name: 'prize', 
                type: 'string'
            },
    
            {
                name: 'status', 
                type: 'string'
            }]
        });
    
        
        var store = new Ext.data.Store({
            model: 'response', 
            proxy: {
                type: 'ajax',
                url : ajaxPath+'parser.php',
                reader: {
                    type: 'json',
                    root: 'result.elem' 
                },
                extraParams:{
                    id : 200,
                    file: 'file'
                }
            },   
            autoLoad: true
        });
    
        
        var template = loadURL(templatePath+'prize.tpl');
    
    
    var dataview = new Ext.DataView({
        id: 'view',
        store: store,           
        tpl: template,          
        itemSelector: 'div.txt' 
    })
    my template:
    Code:
    {date}
    <tpl for=".">
        <div class="txt">
                {name} - {premio}         
        </div>
    </tpl>
    I put the root of the reader with the "result.elem" element, the cycle inside work fine but i don't know how access to the "date" or "status" element...

    any idea?

    tnks

  2. #2
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,449
    Answers
    3997

    Default

    Plug your JSON into http://jsonlint.com/ You will see an error in your JSON. Once you fix this one error, it will work for you.
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Fullstack Engineer
    ________________
    Modus Create is based on the model of an open source team. We’re a remote, global team of experts in our field. To find out more about the work we do, head over to our website.

    Check out my GitHub:
    https://github.com/mitchellsimoens

  3. #3

    Default

    yep, sorry "ctrl+c" error... in my enviroment the josn is right but the parser don't work...

    Code:
    {
        "result": {
            "date": "10/01/2012",
            "elem": [
                {
                    "name": "Name 1",
                    "prize": "Ipad2"
                },
                {
                    "name": "Name 2",
                    "prize": "PlayStation3"
                },
                {
                    "name": "Name 3",
                    "prize": "GalaxyS2"
                },
                {
                    "name": "Name 4",
                    "prize": "GalaxyS2"
                },
                {
                    "name": "Name 5",
                    "prize": "BlueRay"
                }
            ],
            "status": true
        }
    }
    I think the problem is in the root property, and in the nested json elements

  4. #4
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,449
    Answers
    3997

    Default

    Not sure how that would create an error by selecting the code and ctlr+c but ok. Your code is working for me.
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Fullstack Engineer
    ________________
    Modus Create is based on the model of an open source team. We’re a remote, global team of experts in our field. To find out more about the work we do, head over to our website.

    Check out my GitHub:
    https://github.com/mitchellsimoens

  5. #5
    Sencha User
    Join Date
    Jul 2013
    Posts
    11

    Default me too

    how to get date and status ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •