1. #1
    Sencha User
    Join Date
    Jul 2011
    Posts
    12
    Vote Rating
    0
    jason199x is on a distinguished road

      0  

    Default JSON Root

    JSON Root


    I have just started working with EXT JS and JSON and am having trouble when trying to read data from a store. I have been able to populate grids and just write some data to console with very basic JSON objects, but I can't seem to get this form to work.

    Code:
    {
        "name":"value",
        "userbank":{
            "users":[{
                "created_at":"2011-07-06 14:13:34",
                "user_id":"12345",
                "first_name":"Jason",
                "last_name":"Smith",
                "username":"jason199x"
            },{
                "created_at":"2011-07-07 7:07:07",
                "user_id":"77777",
                "first_name":"Alex",
                "last_name":"Smith",
                "username":"alex199x"
            }]
        }
    }
    Here is the Model, Store, and Grid code I am using.

    Code:
    // the model
                Ext.define('User', {extend: 'Ext.data.Model', 
                    fields: [{
                        name: 'user_id',
                        type: 'string'
                    }, {
                        name: 'first_name',
                        type: 'string'
                    }, {
                        name: 'last_name',
                        type: 'string'
                    }, {
                        name: 'username',
                        type: 'string'
                    }],
                    proxy: {
                        type: 'ajax',
                        format: 'json',
                        url: 'embeddedJSON.json',
                        reader: {
                            type: 'json',
                            root: 'users'
                        }
                    }
                });
    
                // the store
                var userStore = new Ext.data.Store({
                    model: 'User',
                    storeId : 'Stores.user'
                    // autoLoad: true
                });
    
                
                Ext.onReady(function(){            
                    
                    var bd = Ext.getBody();
                    userStore.load({
                        callback: function() {
                        }
                    });
                    
                    Ext.create('Ext.grid.Panel', {
                        title: 'TestGrid',
                        store: Ext.data.StoreManager.lookup('Stores.user'),
                        columns:[
                             {header: 'User ID', dataIndex: 'user_id'},
                             {header: 'First Name', dataIndex: 'first_name'},
                             {header: 'Last Name', dataIndex: 'last_name'},
                             {header: 'Username', dataIndex: 'username'}
                        ],
                        height: 200,
                        width: 400,
                        renderTo: Ext.getBody()
                    });
                });
    Can you not just set the root to 'users' to access the two users inside? I might just be missing something so simple (that will probably be the case...) Any feedback would be much appreciated. Thanks!

    -Jason

  2. #2
    Ext JS Premium Member stevil's Avatar
    Join Date
    Nov 2007
    Location
    Denver, CO
    Posts
    1,045
    Vote Rating
    9
    stevil will become famous soon enough

      0  

    Default


    try setting your proxy root property to 'userbank.users'. JSON is unlike XML in that you can't apply a simple XPath like '//rootnodename' to get at a nested root - you have to provide the path from the top of the object.

    stevil

  3. #3
    Sencha User
    Join Date
    Jul 2011
    Posts
    12
    Vote Rating
    0
    jason199x is on a distinguished road

      0  

    Default


    Thank you for your help! I figured it would be something small. This will really help me out in the future.
    Thanks again!
    -Jason

  4. #4
    Ext JS Premium Member stevil's Avatar
    Join Date
    Nov 2007
    Location
    Denver, CO
    Posts
    1,045
    Vote Rating
    9
    stevil will become famous soon enough

      0  

    Default


    Devil's always in the details...

    stevil

Thread Participants: 1

Tags for this Thread

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..." hd porno faketaxi