While attempting to load values from a web service, I encountered the following error message: "ChatStore.data.items[i] is undefined."
The mapping code for extjs is as follows:
ChatStore = new Ext.data.JsonStore({
storeId: 'ChatStore1',
fields: [
{name: "pic_url", mapping: "sender_pic_url"},
{name: "first_name", mapping: "first_name"},
{name: "last_name", mapping: "last_name"},
{name: "message_text", mapping: "message_text"},
{name: "time", mapping: "time"}
]
});
Here is the code used to load data from the web service:
Ext.Ajax.request({
url: 'webservice call',
params: Ext.encode('{"sender_user_id":"' + suid + '","receiver_user_id":"' + ruid + '"}'),
headers: { 'Content-type': 'application/json;charset=utf-8' },
success: function (result, request) {
retData = (result.responseText);
alert(retData);
retData = eval("(" + retData + ")");
if (retData.status == 'success') {
//ChatStore.loadData(retData.result.messages);
//ChatStore.loadData(retData.result);
for (var i = 0; i < retData.result.messages.length; i++) {
if (retData.result.messages[i].message_from == "YES") {
ChatStore.data.items[i].data.pic_url = retData.result.sender_pic_url;
ChatStore.data.items[i].data.first_name = retData.result.sender_name;
}
else {
ChatStore.data.items[i].data.pic_url = retData.result.receiver_pic_url;
ChatStore.data.items[i].data.first_name = retData.result.reciever_name;
}
ChatStore.data.items[i].data.message_text = retData.result.messages[i].message_text;
ChatStore.data.items[i].data.time = retData.result.messages[i].time;
}
// ChatPanel.render('divchat');
messagePanel.hide();
ChatPanel.show();
}
else { alert('error loading first radius'); }
},
failure: function (result, request) {
alert("Error: " + result.statusText);
}
});
return false;
}
Here is the result obtained from the webservice:
{
"status": "success",
"message": "Messages are listing below",
"result": {
"sender_name": "Paul",
"reciever_name": "Clay",
"sender_pic_url": "Images/f1.jpg",
"receiver_pic_url": "Images/f2.jpg",
"messages": [
{
"message_from": "YES",
"message_text": "hi, how r u?",
"time": "12:00am"
},
{
"message_from": "NO",
"message_text": "hi, where are you?",
"time": "1:00am"
},
...
]
}
}
I am unsure of where things went wrong in this process.