0

I am using ExtJS 4. I have created a tree panel as

var treeStore = Ext.create('Ext.data.TreeStore', {
        root: {
            text:'Reports',
            expanded: true,
            children: [
                {
                    id: 'operationalNode',
                    text: 'Operational',
                    children: [{ text: "report1", leaf: true }]
                },
                {
                    id: 'managementNode',
                    text: 'Management',
                    children: [{ text: "report2", leaf: true }]
                },
                {
                    id: 'inventoryNode',
                    text: 'Inventory'
                }
            ]
        }
    });
var treePanel = Ext.create('Ext.tree.TreePanel',{
    animate:true,
    layout:'fit',
    height:400,
    store:treeStore
    });

Now I want to retrieve the 'Operational' child as

Ext.getCmp('operationalNode');

But it returns null.

Why is it so?

How can I retrieve that Node?

Is there any way to retrieve the Node by its name?

Shashwat
  • 2,538
  • 7
  • 37
  • 56

2 Answers2

2

nodes are actual models that have the node interface . so you should just use getNodeById from the treestore

var node = treeStore.getNodeById('operationalNode')

your data is in node.data just like in any other models

nscrob
  • 4,483
  • 1
  • 20
  • 24
0

You gonna need something like this:

Ext.getCmp('id-of-the-view').getView().getSelectionModel().getSelection()[0];
Abdel Raoof Olakara
  • 19,223
  • 11
  • 88
  • 133
Leron
  • 9,546
  • 35
  • 156
  • 257
  • sorry for the comment but he didn't ask to retrieve a selected node – nscrob Jun 14 '12 at 11:26
  • 1
    The people that answer on ExtJS questions are small at number so I decided to share idea even if it's not the best one. – Leron Jun 14 '12 at 11:27
  • As I said I just give some option, I'm not so good in ExtJS, my answer was in case that noone else answer as it happens not once for me. But now he can use yours! – Leron Jun 14 '12 at 11:29
  • it was not an offence sry, i just pointed out the problem so he doesn't start on the wrong path, in extjs using ext.getCmp is very costly because it searches in the whole dom which is pretty big for a normal extjs project. – nscrob Jun 14 '12 at 11:31