PDA

View Full Version : ArrayReader and array format



dougd_unc
12 Jul 2010, 4:23 PM
I have arrays formatted like this:



[
{
id: 23,
firstName: 'John',
lastName: 'Smith',
// ...
},{
id: 48,
firstName: 'Fred',
lastName: 'James',
//...
}
]
And I want to be able to put them in a window and display them when I need to. I have seen examples of loading arrays into a grid where the format is data:[['American History','101','09:30','10:30'],['Physics','201','13:45','14:30'],['Modern Art','133','08:00','09:00']], but I want the object element names to be the names of the fields, not just 0,1,2 etc.

Here is what I have so far:




this.apptStore = new Ext.data.ArrayStore({
fields: [
{name: "id"},
{name: "firstName"},
{name: "lastName"},
// ...
],
data:[]
});

this.displayGrid = new Ext.grid.GridPanel({
store: this.apptStore,
anchor: '100% 100%',
viewConfig: {
forceFit: true
},
cm: new Ext.grid.ColumnModel([{
header: 'First',
width: 20,
dataIndex: 'firstName'
},{
header: 'Last',
width: 100,
dataIndex: 'lastName'
},{
header: 'Start Time',
width: 100,
dataIndex: 'startTime'
},{
// ...
}])
});
Then I put that in a window. The window displays fine, but my problem is, how to load the data in the format given above. I tried this.apptStore.loadData(apptList); But no data displays. I'm wondering if there is some type of configuration that must be given to say that the fieldnames will be based on the element names in the object? How can this be done?

evant
12 Jul 2010, 5:09 PM
You want a JsonStore with no root.

Also, if you're asking for help, in future please post in the help forums.