0

I have this format of json

[
  {
    "docid": "1",
    "doc_title": "Dato' Dr.",
    "doc_name": "xyz",
    "doc_code": "001",
    "doc_category": "3",
    "doc_subcategory": "",  
    "id": "0"
  },
  {
    "docid": "1",
    "doc_title": "Dr.",
    "doc_name": "ABC",
    "doc_code": "002",
    "doc_category": "4",
    "doc_subcategory": "",  
    "id": "0"
  }
]

there are multiple records, I have just included two records

This is my model and parsing code in sencha

Ext.define('User', {
                           extend: 'Ext.data.Model',
                           config: {
                           fields: [
                                    {name: 'docid', type: 'string'},
                                    {name: 'doc_title',  type: 'string'},
                                    {name: 'doc_name',       type: 'string'},
                                    {name: 'doc_code',  type: 'string'},
                                    {name: 'doc_category', type: 'string'},
                                    {name: 'doc_subcategory',       type: 'string'},   
                                    {name: 'id',       type: 'string'},
                                   ]
                           }
                           });

parsing json

var store = Ext.create('Ext.data.Store',
                                 {
                                     autoLoad: true,
                                     model: "User",

                                     listeners:
                                     {
                                        beforeload: function (store,operation,eOpts)
                                        {
                                        }
                                     },                                          

                                     proxy: {
                                        type: 'ajax',
                                        url : 'http://someurl/doctor/search',

                                        reader: {
                                        type: 'json',
                                        rootProperty: 'users',

                                       }
                                      }                               




                                  });

The problem I get only the last record from Json no matter how many records are there in the JSON.

and If I remove the id field (Notice the id fields in Json data) it works fine I can be able to have all records parsed.

Why it is doing so? How can I get all the records parsed with sencha?

1
  • Did the answer below fix your problem. If yes, then accept it, otherwise tell us what did not work and what error you got. Commented Nov 9, 2012 at 21:45

1 Answer 1

1

I'm pretty sure the problem comes from the fat that your specifying a rootProperty in your proxy but they aren't any in you JSON. From that two choices :

Remove the rootProperty

or

Change the structure of your JSON file to something like this :

{
  "users": [
    {
      "docid": "1",
      "doc_title": "Dato' Dr.",
      "doc_name": "xyz",
      "doc_code": "001",
      "doc_category": "3",
      "doc_subcategory": "",
      "id": "0"
    },
    {
      "docid": "1",
      "doc_title": "Dr.",
      "doc_name": "ABC",
      "doc_code": "002",
      "doc_category": "4",
      "doc_subcategory": "",
      "id": "0"
    }
  ]
}

Hope this helps

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.