View Full Version : More nested json confusion

3 Dec 2013, 12:03 PM
I'm being driven insane by this, so I'm hoping someone can point out where I'm messing up. I'm new to extjs, so there's bound to be something wrong in here.

I've got the following JSON being provided via json-rpc though the router.php:

"userInfo": {
"id": "echo",
"dn": "uid=echo,dc=dollhouse,dc=com",
"uid": "echo",
"displayname": "Echo",
"email": "echo@dollhouse.com",
"employeeid": "4",
"altnames": [
{ "altname": "Echo" },
{ "altname": "Caroline Farrell" },
{ "altname": "Jenny" },
{ "altname": "Esther Carpenter" }
"proxyaddresses": [
{ "email": "echo@dollhouse.com" },
{ "email": "caroline@dollhouse.com" },
{ "email": "jenny@dollhouse.com" },
{ "email": "esther@dollhouse.com" }

"userInfo" contains the attributes of a user. The user has a number of properties, and each user has zero or more "altnames", as well as zero or more email aliases (proxyAddresses, in Exchange-speak).

I thought the following data models would work:

Ext.define ('dal.ADUser.userModel', {
extend: 'Ext.data.Model',

fields: [
{ name: 'id', type: 'string' },
{ name: 'dn', type: 'string' },
{ name: 'uid', type: 'string' },
{ name: 'userprincipalname', type: 'string' },
{ name: 'displayname', type: 'string' },
{ name: 'email', type: 'string' },
{ name: 'employeid', type: 'string' }

hasMany: [{
model: 'dal.ADUser.proxyaddressesModel',
name: 'proxyAddresses',
associationKey: 'proxyaddresses'
}, {
model: 'dal.ADUser.altnamesModel',
name: 'altNames',
associationKey: 'altnames'

proxy: {
type: 'direct',
directFn: 'ADLookup.getUserDetailsById',
reader: {
type: 'json',
root: 'userInfo',

... with the nested models being like so:

Ext.define ('dal.ADUser.altnamesModel', {
extends: 'Ext.data.Model',
fields: [ 'altname' ],
belongsTo: 'dal.ADUser.userModel'

Ext.define ('dal.ADUser.proxyaddressesModel', {
extends: 'Ext.data.Model',
fields: [ 'email' ],
belongsTo: 'dal.ADUser.userModel'

When I do a model.load(), I can see the returned record has record.data fields for each of the initial level... "uid", "dn", and so on... but there's no record.proxyAddresses() or record.altNames() available. If I look at the raw data in record.raw, I can see the array of values for record.raw.proxyaddresses and record.raw.altnames... but I'm not supposed to be digging into record.raw, am I?

What's the "right" way of doing this?

3 Dec 2013, 1:31 PM
See if this example will help:

4 Dec 2013, 5:50 AM
Actually, the problem turned out to be the fact that I was using "extends" instead of just "extend" in my child models above. So I'm going to go stick my head in a bucket of cold water now.

But your example was very useful, thanks!

4 Dec 2013, 5:55 AM
Been there .. glad you got it working.