gpt4 book ai didi

javascript - 我怎么知道所选节点是否是树中的叶子? (ExtJS 4)

转载 作者:行者123 更新时间:2023-11-30 18:29:47 25 4
gpt4 key购买 nike

我有一个树面板,我想将一个 Action 与点击这棵树的叶子相关联。我设法将一个与树元素上的每次点击相关联,但我不仅与树叶相关联。

这是我的代码,我尝试了非常简单的功能:(菜单是扩展 tree.Panel 的 View )

Ext.define('WSR.controller.MenuControl', {

extend: 'Ext.app.Controller',

views: [
'Menu',
'Browser'
],

stores: [ 'UserStore' ],

init: function() {

this.control({
'menu': {
itemclick: this.onItemClicked
}
});
},

onItemClicked: function() {
console.log('ItemClicked');
}
});

有人帮我吗?

最佳答案

尝试:

Ext.define('WSR.controller.MenuControl', {

extend: 'Ext.app.Controller',

views: [
'Menu',
'Browser'
],

refs:[
{
selector: 'Menu', //Suggest u to use a selector that is more "tightened" in case you have more trees of this type
ref: 'mynicetree'
}
],

stores: [ 'UserStore' ],

init: function() {

this.control({
'menu': {
//I suggest u use selectionchange instead, itemclick won't work if the use navigate the tree nodes using keyboard, whereas selectionchange fit both
selectionchange: this.loadStuff
}
});
},

loadStuff: function() {

//Assuming you can only select one node at a time (typical use case)
var myTreePanel = this.getMynicetree();
var nodes = myTreePanel.getSelectionModel().selection();
if(!Ext.isEmpty(nodes))
{
var selNode = nodes[0];
if(selNode.get("leaf")) //Assuming your NodeInterface "leaf" property was assigned
{
//Its a leaf
}

//OR
if(selNode.isLeaf())
{
//Its a leaf
}

}
}

});

喂!

关于javascript - 我怎么知道所选节点是否是树中的叶子? (ExtJS 4),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9977777/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com