1. #1
    Sencha Premium Member
    Join Date
    Oct 2011
    Posts
    70
    Answers
    2
    Vote Rating
    0
    angraxs2 is on a distinguished road

      0  

    Default Unanswered: Problems using a simples Ext.data.Store and Json

    Unanswered: Problems using a simples Ext.data.Store and Json


    Hi, i´ve been looking all over for some answer about this, but i couldn´t find it anywhere. Im reading the API Docs for the thousand time, but it is just like mine! I just can´t see what I´m doing wrong.

    I´m trying to use the Ext.Data.Store using a json parse to get 1 single information. Here is my code:

    Code:
    Ext.define('MenusLeftModel', {
    extend: 'Ext.data.Model',
    fields: [
    {name: 'menus', type: 'string'}, ]
    }); var menus = Ext.create('Ext.data.Store', {
    model: 'MenusLeftModel',
    proxy: {
    type: 'ajax',
    url : '../portal/php/menus.php',
    reader: {
    successProperty: 'success',
    type: 'json',
    root: 'config',
    }
    },
    /*data : [
    {'menus': '23456'},
    ],*/
    autoLoad: true,
    }); console.log('MENUS ---> ' + menus.getAt(0).get('menus'));
    My PHP is returning a valid json string:

    Code:
    { "success": true, "config": [{"menus": "235689"}] }
    If I remove the comments on the Data config, it shows it but not the json data. I think its not reading my json string...

    As you can see, its a simple code, with a simple function, but I cant get it to work with my PHP. Any help? Thanks in advance

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,754
    Answers
    3462
    Vote Rating
    827
    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


    Looking at this code:

    Code:
    Ext.define('MenusLeftModel', {
    extend: 'Ext.data.Model',
    fields: [
        {name: 'menus', type: 'string'},
    ]
    });
                                    
    var menus = Ext.create('Ext.data.Store', 
    {
    model: 'MenusLeftModel',
    proxy: {
    type: 'ajax',
    url : '../portal/php/menus.php',
    reader: {
    successProperty: 'success',
    type: 'json',
    root: 'config',
    }
    },
    /*data : [
    {'menus': '23456'},
    ],*/
    autoLoad: true,
    });
                                    
    console.log('MENUS ---> ' + menus.getAt(0).get('menus'));
    The store is setup properly for your JSON. The console.log will fire right after the store is created but the loading is still happening. You need to add a listener for the load event and do the console.log there:

    Code:
    Ext.define('MenusLeftModel', {
        extend: 'Ext.data.Model',
        fields: [
            {name: 'menus', type: 'string'},
        ]
    });
                                    
    var menus = Ext.create('Ext.data.Store', {
        model: 'MenusLeftModel',
        proxy: {
            type: 'ajax',
            url : '../portal/php/menus.php',
            reader: {
                successProperty: 'success',
                type: 'json',
                root: 'config',
            }
        },
        autoLoad: true,
        listeners : {
            load : function(store) {
                console.log(store.getAt(0).get('menus'));
            }
        }
    });
    Now that should 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 Premium Member
    Join Date
    Oct 2011
    Posts
    70
    Answers
    2
    Vote Rating
    0
    angraxs2 is on a distinguished road

      0  

    Default


    Thank you

    I thought it was a problem on my JSON. Now i can set my menus properly!


    Thanks again;

Thread Participants: 1

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..."