PDA

View Full Version : How do I use the callback of store.load to loop through the returned records?



Maxeta
18 Nov 2013, 7:12 AM
Running this:



var x = Ext.getStore('mystore');
x.load({
callback: function (records, operation, success) {
for (var i = 0; i < records.length; i++) {
alert(records[i]);
}
}
});


Show me that records is populated and each records is an object... but what is it's type? I think records is an array of Ext.data.Model, but I'm not sure, I can't seem to access any Model properties or methods...

I need to be able to access the individual fields when loading something like the following:


{
"success": true,
"data": [
{
"ID": 1,
"Name": "Name1",
},
{
"ID": 2,
"Name": "Name2",
},
{
"ID": 3,
"Name": "Name3",
}
]
}



UPDATE: Is this right?

After much poking and prodding I was able to achieve the basics I needed, but is this correct? Is there a better way?


callback: function (records, operation, success) {
for (var i = 0; i < records.length; i++) {
alert(records[i].getData().Name);
}
}

scottmartin
18 Nov 2013, 7:48 AM
To improve on this, you can use records[i].get('field')

Scott.