Afshin Mehrabani
Afshin Mehrabani

Reputation: 35009

Click event on tree's children/node

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?

Upvotes: 7

Views: 15715

Answers (1)

sra
sra

Reputation: 23983

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

Upvotes: 8

Related Questions