PDA

View Full Version : TreeStore with auto field mappings?



nikolawannabe
2 May 2011, 5:20 PM
I have a model that looks something like this:


Ext.regModel('TreeItem', {
fields: [
{ name: 'ItemId', type: 'int' },
{ name: 'ItemType', type: 'string' },
{ name: 'Article', type: 'auto' },
{ name: 'Container', type: 'auto' },
{ name: 'Category', type: 'auto'}]
});

The ItemType indicates whether that specific item should be rendered as an Article, Container, or Category. Each of the Article, Container, and Category objects has an associated ArticleName, ContainerName, and CategoryName.

I'd like to render these names in a NestedList based on the record's ItemType. So I overrode the getItemTextTpl like this:


getItemTextTpl: function (recordnode)
{
var template = '<div class="{ItemType}-icon"></div>';
if (recordnode.firstChild.attributes.record.data["ItemType"] == 'Article')
{
template += recordnode.firstChild.attributes.record.data['Article']["ArticleName"];
}
if (recordnode.firstChild.attributes.record.data["ItemType"] == 'Container')
{
template += recordnode.firstChild.attributes.record.data['Container']["ContainerName"];
}
if (recordnode.firstChild.attributes.record.data["ItemType"] == 'Category')
{
template += recordnode.firstChild.attributes.record.data['Category']["CategoryName"];
}
return template;
},

However, it appears that getItemTextTpl is only called once for each level of the tree, so there's no way to render the information for each list item.

Does anyone have suggestions on how to accomplish this? Thanks in advance.