View Full Version : Tree node custom attributes

30 Aug 2011, 8:16 AM
Based on this article
I'd like to access custom fields in tree node but in extjs4.
There do not exist:
How can I access custom attributes?

30 Aug 2011, 10:20 AM
Tree nodes are now backed by records. By default the model for a tree has one field, text, but you can add others. These extra fields can either be used as other columns in the tree or as attributes the way you describe.

If you're explicitly creating a TreeStore then just add the fields there. If you aren't you can specify them on the treepanel.

Here's an example using a listener on the tree's selection model, there are many other ways you might access the record depending on your circumstances:

var tree = Ext.create('Ext.tree.Panel', {
fields: ['text', 'customfield']

tree.getSelectionModel().on('select', function(sm, record) {
var value = record.get('customfield');