Results 1 to 6 of 6

Thread: how to load json in extjs

  1. #1

    Exclamation how to load json in extjs

    i
    am loading the values coming from web service but i get following error message. ChatStore.data.items[i] is undefined.
    Mapping code for extjs is



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

    ]

    }); code for loading data from 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;
    }
    My webservice result is:-----

    {
    "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"
    }
    ]
    }
    }i
    dont know where the things go wrong.

  2. #2
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,379

    Default

    You should use a proxy and reader on the store and allow it to do the loading that way it will handle it all and you won't need the Ajax request.

    You also shouldn't do things like:

    Code:
    ChatStore.data.items[i].data.pic_url = retData.result.sender_pic_url;
    You should use the add or insert method on the store passing an object of data.
    Mitchell Simoens @LikelyMitch

    Check out my GitHub:
    https://github.com/mitchellsimoens

    Posts are my own, not any current, past or future employer's.

  3. #3

    Default

    how the mapping problem is solve.....
    because i want to set pic_url=sender_pic_url & receiver_pic_url....
    when i use insert method then it gives following error :----------
    record.join is not a function

  4. #4
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,379

    Default

    You can use the convert config on the field.

    http://docs.sencha.com/ext-js/4-0/#!...ld-cfg-convert
    Mitchell Simoens @LikelyMitch

    Check out my GitHub:
    https://github.com/mitchellsimoens

    Posts are my own, not any current, past or future employer's.

  5. #5

    Default

    Thanks..............
    I use the convert config & it's working fine.....
    Really thanks...

  6. #6

    Default

    hi friend... i am stuck with another problem .. i dont know how to create nested json in extjs..
    i want to create this param filed so that i can send it to my web service




    var parms={
    "quiz_id":"120","owner_id":"1","solver_id":"1",
    "answers":
    [
    {
    "answer_text" : "YES",
    "question_id" : "1"
    },
    {
    "answer_text" : "NO",
    "question_id" : "2"
    },
    {
    "answer_text" : "YES",
    "question_id" : "3"
    },
    {
    "answer_text" : "YES",
    "question_id" : "4"
    },
    {
    "answer_text" : "YES",
    "question_id" : "5"
    }
    ]
    };


    i am stuck with the contnets inside the answers i dont know how to create it dynamically .

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •