PDA

View Full Version : XTemplate with nested json



jbird526
16 Nov 2010, 9:53 AM
Ext JS Library 3.2.1
Having issue creating an XTemplate that will work with this string. I cannot change the string, it isnt up to me. I cannot go down more than 2 levels in the array. Whenever I run the code FB tells me that enrollments is undefined. If were able to eliminate the items array and move the enrollments and preferences up a level it works. I have been thru the API and tried several configurations but no luck.


var data = {
"actions":[
{
"actionId":"editUser",
"actionUrl":"system/updateUserInformation"
},
{
"actionId":"getRoles",
"actionUrl":"system/getSystemRoles"
}
],
"success":true,
"root":[
{
"adminUuid":"bbce",
"adminEmplid":"NGDVFAC02",
"adminUName":"ngdvfac2_test",
"adminDName":"Faculty2 DevTest",
"adminFName":"Faculty2",
"adminMName":"",
"adminLName":"DevTest",
"adminEmail":"",
"adminStr1":"",
"adminStr2":"",
"adminCity":"",
"adminZip":"",
"adminCountry":"",
"adminSchool":1,
"adminHPhone":"",
"adminOPhone":"",
"adminPwd":"",
"adminBDate":"11/30/1899 12:00AM",
"adminSysRoleId":"default_user",
"adminLLogin":"",
"items":[
{

"enrollments":[
{
"adminRoleId":"4",
"adminRoleDesc":"primary faculty member in a specific class",
"adminSectionId":"04733a",
"adminSemester":"1002",
"adminSubject":"TEST",
"adminCourse":"TEST101",
"adminSectionNumber":"0106"
},
{
"adminRoleId":"4",
"adminRoleDesc":"primary faculty member in a specific class",
"adminSectionId":"bbcd2f2",
"adminSemester":"0906",
"adminSubject":"NGDV",
"adminCourse":"NGDV100",
"adminSectionNumber":"0002"
},
{
"adminRoleId":"4",
"adminRoleDesc":"primary faculty member in a specific class",
"adminSectionId":"bd5dc5e883",
"adminSemester":"0906",
"adminSubject":"NGDV",
"adminCourse":"NGDV200",
"adminSectionNumber":"0002"
},
{
"adminRoleId":"4",
"adminRoleDesc":"primary faculty member in a specific class",
"adminSectionId":"c0db94788",
"adminSemester":"1009",
"adminSubject":"NGDV",
"adminCourse":"NGDV200",
"adminSectionNumber":"0002"
},
{
"adminRoleId":"4",
"adminRoleDesc":"primary faculty member in a specific class",
"adminSectionId":"c0e89dcc",
"adminSemester":"1009",
"adminSubject":"NGDV",
"adminCourse":"NGDV100",
"adminSectionNumber":"0002"
}
]
},
{

"preferences":[
{
"prefKey":"aware",
"prefValue":"false"
},
{
"prefKey":"quote",
"prefValue":"false"
},
{
"prefKey":"editor",
"prefValue":"false"
}
]
}
]
}
]
};



Ext.umuc.UserSearchInformation = Ext.extend(Ext.Panel, {

initComponent:function() {

var config = {

tpl: new Ext.XTemplate (

'<tpl for="root">',
'<div style = "padding: 5px; font-size:90%; font-family: Verdana, Arial, Helvetica, sans-serif;">',
'<div><b>System Role ID</b>: {adminSysRoleId}</br></div>',
'<div><b>Empl ID</b>: {adminEmplid}<br></div>',
'<div><b>Login</b>: {adminUName}</div>',
'<div><b>Full Name</b>: {adminDName}</div>',
'<div><b>First Name</b>: {adminFName}</div>',
'<div><b>Middle Name</b>: {adminMName}</div>',
'<div><b>Last Name</b>: {adminLName}</div>',
'<div><b>Email</b>: {adminEmail}</div>',
'<div><b>Street 1</b>: {adminStr1}</div>',
'<div><b>Street 2</b>: {adminStr2}</div>',
'<div><b>City</b>: {adminCity}</div>',
'<div><b>Zip</b>: {adminZip}</div>',
'<div><b>Country</b>: {adminCountry}</div>',
'<div><b>School</b>: {adminSchool}</div>',
'<div><b>Home Phone</b>: {adminHPhone}</div>',
'<div><b>Other Phone</b>: {adminOPhone}</div>',
'<div><b>Password</b>: {adminPwd}</div>',
'<div><b>Birth Date</b>: {adminBDate}</div>',
'<div><b>Last Login</b>: {adminLLogin}</div>',

'<div><b>Preferences:</b></div>',
'<tpl for="preferences">',
'<div style = "color:blue; padding-left:10px;"><b>Communication</b>: {}</div>',
'<div style = "color:blue; padding-left:10px;"><b>Platform</b>: {}</div>',
'<div style = "color:blue; padding-left:10px;"><b>Editor</b>: {}</div>',
'</tpl>',

'<div><b>Enrollments:</b></div>',
'<tpl for="enrollments">',
'<div style = "color:blue; padding-left:10px; font-size:90%; font-family: Verdana, Arial, Helvetica, sans-serif;">{adminSemester}{adminCourse}{adminSectionNumber}</div>',
'</tpl>',

'</div>',

'</tpl>'
).compile(),



tbar: tb = new Ext.Toolbar({
id: 'tool-bar',
items:[
{
text:'Index',
disabled: true
},{
text:'Edit',
disabled: true

},{
text:'Reset Password',
disabled: true
},{
text:'Remove User Account',
disabled: true
},{
text:'Compute Class List',
disabled: true
},
{
text: 'Role Change',
json: this.json,
handler: this.getSystemRole
},
{
text: 'Preference Change',
json: this.json,
handler: this.preferenceChange
},
{
text: 'Manage User Messaging',
json: this.json,
handler: this.launchMessaging
}
]

})


};//eo config
Ext.apply(this, Ext.apply(this.initialConfig, config));

Ext.umuc.UserSearchInformation.superclass.initComponent.apply(this, arguments);


}, // e/o function initComponent

onRender:function() {

Ext.umuc.UserSearchInformation.superclass.onRender.apply(this, arguments);

this.tpl.overwrite(this.body, data);

}, // e/o function onRender