View Full Version : Store.loadData() Question

14 May 2010, 5:03 AM
I have a User JSON Object that looks as follows;

"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
The question I have, is I have a datastore setup as follows;

this.aUserGroupRecord = Ext.data.Record.create([
{name: 'id', mapping: 'id'},
{name: 'groupId', mapping: 'groupId'},
{name: 'userId', mapping: 'userId'},
{name: 'code', mapping: 'code'},
{name: 'name', mapping: 'name'},
{name: 'description', mapping :'description'}

this.aUserGroupReader = new Ext.data.JsonReader(
root: 'groups',
idProperty: 'id',
successProperty: 'success'
}, this.aUserGroupRecord);

this.aUserGroupStore = new Ext.data.Store(
id :'userGroupStore',
autoSave: false, //I want to manage the update directly.
storeId: 'userGroupStore',
reader: this.aUserGroupReader,
writer: this.aUserGroupWriter,
proxy: this.aUserGroupProxy,
idProperty: 'id',
successProperty: 'success',
baseParams: {entity:'group', user_id:-1},
listeners: {
exception: function() {
The way I want to load data into this store, is by using the loadData(records) method. The line looks like this

The userRecord is set to a currently selected record in another store, and when I reference the userRecord.get('groups') I get the data I want, the problem is that when I call the get('groups') it returns the data and I lose the root of 'groups' which I need as this is a potential array of groups.

Is there a way to maintain the groups root when calling get('groups')? If I can maintain that, things are looking good.

14 May 2010, 5:11 AM
I've actually found a solution to this, just wondering if it is a good approach/best practice.

I have changed the code to


This has the desired effect, it loads into the store perfectly.

Now... onto the delete aspect if the end-user removes a record from the store now that it is populated ;)