PDA

View Full Version : Access objects attribute in Template of Listview



htammen
19 Nov 2010, 3:30 PM
This is probably a silly question but I donīt get it.
In my view I use a Listview. This is connected to a JSONStore. The Java server send the following JSON response:


{"success":true,
"items":[
{"class":"com.company.MyClass",
"id":1,
"attrib1":"Hamburg",
"attrib2":"20334",
"attrib3":"998",
"dateCreated":"2010-11-19T13:13:26Z",
"attrib4":{"enumType":"com.company.enums.MyEnum","name":"NS_PV"},
"lastUpdated":"2010-11-19T13:13:26Z",
"attrib5":12},
...(some more objects of type MyClass)
]
}

In the Listview that is bound to the items array there is a column that displays "attrib4". If I donīt do anything special with the column "[object Object]" is displayed. So I set the tpl property to {attrib4.name} to display "NS_PV". This works of course in other javascripts but inside the template I get the javascript error "attrib4 is not defined"
How can I access the attribute name of the object attrib4 inside a ExtJS Template?

htammen
20 Nov 2010, 6:49 AM
I found a way how it works but I canīt set it in Ext Designer. This may be caused by my bad Javascript knowledge. Can anyone help?

In the initComponent of my enclosing Viewport I set the XTemplate of the column like this (where lv is the Listview):


this.lv.columns[3].tpl = new Ext.XTemplate(
'{attrib4:this.getName}',
{
getName: function(val, record) {return val.name;}
}
);