Question

Using sencha touch 2, am trying to render a nestedlist with json proxy. The json looks like

[
  {
    "start": "0"
  },
  {
    "format": "json"
  },
  .......
  {
    "GetFolderListing": [
        {
            "folder": {
                "total": 0,
                "id": "Calendar",
                "name": "Calendar",
                "unread": 0,
            }
        },
        {
            "folder": {
                "total": 0,
                "id": "Contacts",
                "name": "Contacts",
                "unread": 0,
            }
        },
  .......

I want to use GetFolderListing.folder.name as the displayField My store looks like

Ext.define('foo.store.FolderListing', {
extend: 'Ext.data.TreeStore',
require: ['foo.model.FolderListing'],
config: {
    model: 'foo.model.FolderListing',
    recursive: true,
    proxy: {
    type: 'jsonp',
    url: 'http://localhost/?xx=yy&format=json',
    callbackKey: "jsoncallback",
    reader: {
        type: 'json',
        rootProperty: 'GetFolderListing',
        record: 'folder'
    }
}
 }
});

Right now all i get is an error Uncaught TypeError: Cannot read property 'id' of undefined

Could anyone provide insight on how to solve this or debug it better or how to do custom parsing and pass items back to a store?

Thanks

======== Update - in order for the rootProperty to work in the reader, the json had to be a jsonobject rather than a json array e.g.

{
"GetFolderListing": [
    {
        "folder": {
            "total": 0,
            "id": "Contacts",
            "name": "Contacts",
            "unread": 0,
            "leaf": "true"
        }
    },
    {
        "folder": {
            "total": 0,
            "id": "Conversation Action Settings",
            "name": "Conversation Action Settings",
            "unread": 0,
            "leaf": "true"
        }
    },
    .......
Was it helpful?

Solution

Your JSON looks like an array. The error message means that the code tries to access a property of a undefined variable or property.

My first guess would be that the reader is not properly configured for that array type JSON format.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top