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