2013-02-06 10 views
5

Sono davvero confuso dall'oggetto dell'albero ExtJs, c'è qualcosa che non va nel mio codice ma non so cosa.Fare clic sull'evento sui figli dell'albero/nodo

Considerate che ho questo codice:

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() 
}); 

Come posso associare un click evento per i bambini/foglia del mio albero?

risposta

8

Ti piace?

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); 
     } 
    } 
}); 

vedono questo JSFiddle

+0

Ok, quindi cosa succede quando clicco su per esempio 'detention' nodo? –

+0

@AfshinMehrabani L'evento viene attivato. Se la mia modifica, ho aggiunto un JSFiddle – sra

+0

Oh ragazzo! è fantastico, ** funziona **. Quindi ho solo un'altra domanda, lavori per Sencha? –

Problemi correlati