Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/392.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在extjs中加载json_Javascript_Ajax_Json_Extjs - Fatal编程技术网

Javascript 如何在extjs中加载json

Javascript 如何在extjs中加载json,javascript,ajax,json,extjs,Javascript,Ajax,Json,Extjs,我正在加载来自web服务的值,但收到以下错误消息。 ChatStore.data.items[i]未定义 extjs的映射代码是 ChatStore = new Ext.data.JsonStore({ storeId: 'ChatStore1', fields: [ {name: "pic_url", mapping: "sender_pic_url"}, {name: "fir

我正在加载来自web服务的值,但收到以下错误消息。 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"}

                ]        

     }); 
用于从webservice加载数据的代码

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

我不知道哪里出了问题。

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

您需要在存储区中指定Json代理对象,然后存储区将自动加载自身,并且所有项目都将在不使用任何特殊代码的情况下填充,或者

您需要使用store.add()函数将新项目添加到商店中


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

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

您需要在存储区中指定Json代理对象,然后存储区将自动加载自身,并且所有项目都将在不使用任何特殊代码的情况下填充,或者

您需要使用store.add()函数将新项目添加到商店中


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

谢谢。。我在这里升级我的代码。。。我用调试器ChatStore.data.items[i].data.pic\u url测试了这个值,但我不知道如何在存储中加载…不需要做所有这些。检查存储的代理属性。在这里,您可以指定您的服务器具有Json代理和URL。然后你只需调用store.load(),它会自动执行Ajax请求,你会自动在存储中获取数据。我知道store.load方法,但我会一次性获取pic_url和名称,我必须与发送方pic和接收方pic进行映射,并在11时在dataview中使用。即基于webserviceok。然后,为了访问和更改存储中的项目,请使用store.getAt(i)获取模型,然后设置('property_name')以更改字段。或者查看store的每个()方法。不要直接转到data.items.ChatStore.data.items[i].data.pic\u url=retData.result.sender\u pic\u url;这个方法有用与否。。。我现在能用什么谢谢。。我在这里升级我的代码。。。我用调试器ChatStore.data.items[i].data.pic\u url测试了这个值,但我不知道如何在存储中加载…不需要做所有这些。检查存储的代理属性。在这里,您可以指定您的服务器具有Json代理和URL。然后你只需调用store.load(),它会自动执行Ajax请求,你会自动在存储中获取数据。我知道store.load方法,但我会一次性获取pic_url和名称,我必须与发送方pic和接收方pic进行映射,并在11时在dataview中使用。即基于webserviceok。然后,为了访问和更改存储中的项目,请使用store.getAt(i)获取模型,然后设置('property_name')以更改字段。或者查看store的每个()方法。不要直接转到data.items.ChatStore.data.items[i].data.pic\u url=retData.result.sender\u pic\u url;这个方法有用与否。。。我现在能用什么
{
    "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"
            }
        ]
    }
}