gpt4 book ai didi

javascript - 如何在extjs中加载json

转载 作者:行者123 更新时间:2023-11-30 06:42:40 25 4
gpt4 key购买 nike

我正在加载来自网络服务的值,但我收到以下错误消息。ChatStore.data.items[i] 未定义。

extjs的映射代码是

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"}

]

});

从网络服务加载数据的代码

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;
}

我的网络服务结果是:-----

{
"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"
},
{
"message_from": "NO",
"message_text": "Dear, you are invited for the meeting",
"time": "2:00am"
},
{
"message_from": "YES",
"message_text": "hi, how r u?",
"time": "12:00am"
},
{
"message_from": "NO",
"message_text": "hi, where are you?",
"time": "1:00am"
},
{
"message_from": "NO",
"message_text": "Dear, you are invited for the meeting",
"time": "2:00am"
},
{
"message_from": "NO",
"message_text": "Ya ill be there",
"time": "2:00am"
},
{
"message_from": "NO",
"message_text": "at what time party starts",
"time": "2:00am"
},
{
"message_from": "YES",
"message_text": "6Oclock in the evening",
"time": "2:00am"
},
{
"message_from": "NO",
"message_text": "Who will the chief guest",
"time": "2:00am"
},
{
"message_from": "YES",
"message_text": "our city mayor",
"time": "2:00am"
}
]
}
}

我不知道哪里出了问题。

最佳答案

您不能只将项目分配给 store.items 数组。首先它是未定义的。其次,总体而言这不是正确的方法。

您需要在商店中指定 Json 代理对象,然后商店将自动加载并填充所有项目,而无需任何特殊代码,或者

您需要使用 store.add() 函数将新商品添加到商店。

从您的代码看来您正在使用 store.load() 方法,不是吗?您能否发布更多关于加载数据的准确程度以及您与服务器的通信方式的代码。

关于javascript - 如何在extjs中加载json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9654081/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com