PDA

View Full Version : Get Json store data



thomsonzh
18 Jun 2013, 12:42 PM
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,

Frith
19 Jun 2013, 4:57 AM
You need to set root in your reader to users.



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

thomsonzh
19 Jun 2013, 6:50 AM
Thanks Frith, I am using Extjs3.*. So do you have any suggestion for get user data [.......] as var data using extjs3?

Many thanks,

Frith
20 Jun 2013, 5:43 AM
Ext 3.3 example. Modify to suit your fields, save it as jstoreUsers.js and include in your main html page.



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();