1. #1
    Sencha User
    Join Date
    Nov 2011
    Posts
    2
    Vote Rating
    0
    elfflames is on a distinguished road

      0  

    Question Unanswered: Ext.data.Store reader root, json problem

    Unanswered: 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 - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,541
    Vote Rating
    872
    Answers
    3566
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    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 @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Nov 2011
    Posts
    2
    Vote Rating
    0
    elfflames is on a distinguished road

      0  

    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 - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,541
    Vote Rating
    872
    Answers
    3566
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    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 @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  5. #5
    Sencha User
    Join Date
    Jul 2013
    Posts
    11
    Vote Rating
    0
    aflext is on a distinguished road

      0  

    Default me too

    me too


    how to get date and status ?

Thread Participants: 2