本文介绍了在树的子节点上单击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的很困惑的ExtJs树对象,我的代码有问题,但我不知道什么。



考虑我有这个代码:

  var store = Ext。 create('Ext.data.TreeStore',{
root:{
expanded:true,
children:[
{text:retention,leaf:true},
{text:家庭作业,扩展:true,children:[
{text:book report,leaf:true},
{text:alegrbra,leaf:true}
]},
{text:买彩票,leaf:true}
]
}
});

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

如何将点击事件绑定到我的树的孩子/叶子?

解决方案

喜欢这样?

  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:买彩票,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);
}
}
});

看到这个


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 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

这篇关于在树的子节点上单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 17:34