Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Click event on tree's children/node

Tags:

extjs

extjs4

I really confused by ExtJs tree object, something is wrong with my code but I don't know what.

Consider I have this code:

var store = Ext.create('Ext.data.TreeStore', {
    root: {
        expanded: true,
        children: [
            { text: "detention", leaf: true },
            { text: "homework", expanded: true, children: [
                { text: "book report", leaf: true },
                { text: "alegrbra", leaf: true}
            ] },
            { text: "buy lottery tickets", leaf: true }
        ]
    }
});

Ext.create('Ext.tree.Panel', {
    title: 'Simple Tree',
    width: 200,
    height: 150,
    store: store,
    rootVisible: false,
    renderTo: Ext.getBody()
});

How can I bind a click event to my tree's children/leaf?

like image 486
Afshin Mehrabani Avatar asked Feb 06 '13 05:02

Afshin Mehrabani


1 Answers

Like so?

var store = Ext.create('Ext.data.TreeStore', {
    root: {
        expanded: true,
        children: [
            { text: "detention", leaf: true },
            { text: "homework", expanded: true, children: [
                { text: "book report", leaf: true },
                { text: "alegrbra", leaf: true}
            ] },
            { text: "buy lottery tickets", leaf: true }
        ]
    }
});

Ext.create('Ext.tree.Panel', {
    title: 'Simple Tree',
    width: 200,
    height: 150,
    store: store,
    rootVisible: false,
    renderTo: Ext.getBody(),
    listeners: {
        itemclick: function(s,r) {
                alert(r.data.text);
        }
    }
});

see this JSFiddle

like image 143
sra Avatar answered Oct 23 '22 13:10

sra