Results 1 to 4 of 4

Thread: Get Json store data

  1. #1
    Sencha User
    Join Date
    Dec 2010
    Location
    Toronto
    Posts
    62
    Answers
    1
    Vote Rating
    1
      0  

    Default Answered: Get Json store data

    Hi,

    I have a Ext.data.JsonStore,
    {
    "users": [
    {
    "id": 16,
    "username": "acme@acme.com",
    "password": "acme",
    "firstname": "Acme",
    "lastname": "Acme",
    "expirydate": "2010-06-23",
    "creationdate": "null",
    "role_id": "1",
    "email": "acme@acme.com",
    "address": "Address for acme",
    "subscriber_id": "1",
    "enabled": "1",
    "passwordchange": "1",
    "groups": [
    {
    "id": "57",
    "groupId": 2,
    "userId": 16,
    "code": "SPROJ",
    "name": "SR. Project Manager",
    "description": "Senior Project Manager"
    },
    {
    "id": "58",
    "groupId": 1,
    "userId": 16,
    "code": "ADMIN",
    "name": "Adminisrator",
    "description": "Administer the System"
    }
    ]
    }
    ],
    "success": true,
    "results": 1,
    "totalRecords": 1
    }
    how can I get users
    ?
    [{

    "id": 16,
    "username": "acme@acme.com",
    "password": "acme",
    "firstname": "Acme",
    "lastname": "Acme",
    "expirydate": "2010-06-23",
    "creationdate": "null",
    "role_id": "1",
    "email": "acme@acme.com",
    "address": "Address for acme",
    "subscriber_id": "1",
    "enabled": "1",
    "passwordchange": "1",
    "groups": [
    {
    "id": "57",
    "groupId": 2,
    "userId": 16,
    "code": "SPROJ",
    "name": "SR. Project Manager",
    "description": "Senior Project Manager"
    },
    {
    "id": "58",
    "groupId": 1,
    "userId": 16,
    "code": "ADMIN",
    "name": "Adminisrator",
    "description": "Administer the System"
    }
    ]


    var tempdata= store.getById('users'); it is not working.

    Please advise,
    Many thanks,

  2. Ext 3.3 example. Modify to suit your fields, save it as jstoreUsers.js and include in your main html page.

    Code:
    jsStoreUsers = Ext.extend(Ext.data.JsonStore, {
        constructor: function(cfg) {
            cfg = cfg || {};
            jsStoreUsers.superclass.constructor.call(this, Ext.apply({
                storeId: 'storeUsers',
                url: 'your-url.php',
                root: 'users',
                messageProperty: 'msg',
                fields: [
                    {
                        name: 'actionID',
                        type: 'int'
                    },
                    {
                        name: 'actionArea',
                        type: 'int'
                    },
                    {
                        name: 'actionTracker',
                        type: 'int'
                    },
                    {
                        name: 'actionCat',
                        type: 'int'
                    },
                    {
                        name: 'originator',
                        type: 'int'
                    },
                    {
                        name: 'dtraised',
                        type: 'date',
                        dateFormat: 'Y-m-d H:i:s'
                    },
                    {
                        name: 'assignedto',
                        type: 'int'
                    },
                    {
                        name: 'priority',
                        type: 'int'
                    },
                    {
                        name: 'risk',
                        type: 'int'
                    },
                    {
                        name: 'status',
                        type: 'int'
                    },
                    {
                        name: 'source',
                        type: 'string'
                    },
                    {
                        name: 'subject',
                        type: 'string'
                    },
                    {
                        name: 'dttarget',
                        dateFormat: 'Y-m-d H:i:s',
                        type: 'date'
                    },
                    {
                        name: 'dtclosed',
                        dateFormat: 'Y-m-d H:i:s',
                        type: 'date'
                    },
                    {
                        name: 'dtupdated',
                        dateFormat: 'Y-m-d H:i:s',
                        type: 'date'
                    },
                    {
                        name: 'originalpost',
                        type: 'int'
                    },
                    {
                        name: 'statusID',
                        type: 'int'
                    },
                    {
                        name: 'areaName'
                    },
                    {
                        name: 'catName'
                    },
                    {
                        name: 'riskDesc'
                    },
                    {
                        name: 'priorityDesc'
                    },
                    {
                        name: 'trackerName'
                    },
                    {
                        name: 'statusDesc'
                    },
                    {
                        name: 'assignedtoname'
                    },
                    {
                        name: 'originatorname'
                    }
                ]
            }, cfg));
        }
    });
    new jsStoreUsers();

  3. #2
    Sencha User
    Join Date
    Jan 2010
    Location
    Northern Ireland
    Posts
    59
    Answers
    2
    Vote Rating
    2
      0  

    Default

    You need to set root in your reader to users.

    Code:
    Ext.define('EdirUser', {
        extend: 'Ext.data.Model',
        fields: [
                    //put your fields here
                ]
    });
    
    
    Ext.define('MyApp.store.jsStoreEdir', {
        extend: 'Ext.data.Store',
    
    
        constructor: function(cfg) {
            var me = this;
            cfg = cfg || {};
            me.callParent([Ext.apply({
                    model: 'EdirUser',
                storeId: 'jsStoreEdir',
                pageSize: 10,
                proxy: {
                    type: 'ajax',
                    url: 'myurl-to-get-users.php',
                    reader: {
                        type: 'json',
                        root: 'users',
                        totalProperty: 'totalRecords'
                    }
                    
                }
                
            }, cfg)]);
        }
    });

  4. #3
    Sencha User
    Join Date
    Dec 2010
    Location
    Toronto
    Posts
    62
    Answers
    1
    Vote Rating
    1
      0  

    Default

    Thanks Frith, I am using Extjs3.*. So do you have any suggestion for get user data [.......] as var data using extjs3?

    Many thanks,

  5. #4
    Sencha User
    Join Date
    Jan 2010
    Location
    Northern Ireland
    Posts
    59
    Answers
    2
    Vote Rating
    2
      0  

    Default

    Ext 3.3 example. Modify to suit your fields, save it as jstoreUsers.js and include in your main html page.

    Code:
    jsStoreUsers = Ext.extend(Ext.data.JsonStore, {
        constructor: function(cfg) {
            cfg = cfg || {};
            jsStoreUsers.superclass.constructor.call(this, Ext.apply({
                storeId: 'storeUsers',
                url: 'your-url.php',
                root: 'users',
                messageProperty: 'msg',
                fields: [
                    {
                        name: 'actionID',
                        type: 'int'
                    },
                    {
                        name: 'actionArea',
                        type: 'int'
                    },
                    {
                        name: 'actionTracker',
                        type: 'int'
                    },
                    {
                        name: 'actionCat',
                        type: 'int'
                    },
                    {
                        name: 'originator',
                        type: 'int'
                    },
                    {
                        name: 'dtraised',
                        type: 'date',
                        dateFormat: 'Y-m-d H:i:s'
                    },
                    {
                        name: 'assignedto',
                        type: 'int'
                    },
                    {
                        name: 'priority',
                        type: 'int'
                    },
                    {
                        name: 'risk',
                        type: 'int'
                    },
                    {
                        name: 'status',
                        type: 'int'
                    },
                    {
                        name: 'source',
                        type: 'string'
                    },
                    {
                        name: 'subject',
                        type: 'string'
                    },
                    {
                        name: 'dttarget',
                        dateFormat: 'Y-m-d H:i:s',
                        type: 'date'
                    },
                    {
                        name: 'dtclosed',
                        dateFormat: 'Y-m-d H:i:s',
                        type: 'date'
                    },
                    {
                        name: 'dtupdated',
                        dateFormat: 'Y-m-d H:i:s',
                        type: 'date'
                    },
                    {
                        name: 'originalpost',
                        type: 'int'
                    },
                    {
                        name: 'statusID',
                        type: 'int'
                    },
                    {
                        name: 'areaName'
                    },
                    {
                        name: 'catName'
                    },
                    {
                        name: 'riskDesc'
                    },
                    {
                        name: 'priorityDesc'
                    },
                    {
                        name: 'trackerName'
                    },
                    {
                        name: 'statusDesc'
                    },
                    {
                        name: 'assignedtoname'
                    },
                    {
                        name: 'originatorname'
                    }
                ]
            }, cfg));
        }
    });
    new jsStoreUsers();

Posting Permissions

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