如何在 ExtJS 4 中的树节点上设置 singleClickExpand

发布于 2025-01-06 20:16:38 字数 201 浏览 2 评论 0原文

在 ExtJS 树上展开节点的默认操作是双击。

在版本 4 之前,TreeNode 配置中有 singleClickExpand 属性。

如何在 ExtJS 版本 4 树上应用 singleClickExpand 行为?

是否有此行为的配置属性而不设置事件侦听器?

谢谢。

The default action to expand a node on ExtJS tree is double-click.

Before version 4, there is singleClickExpand property in TreeNode configuration.

How to apply singleClickExpand behavior on ExtJS version 4 tree ??

Is there a configuration property for this behavior without setting event listener??

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

素染倾城色 2025-01-13 20:16:38

我花了一些时间寻找同样的东西。我觉得我可以明确地回答你的问题...
不,没有它的配置选项。
我必须设置一个点击处理程序。无论如何,我需要一个来实现叶子点击的功能:

var tree = Ext.create('Ext.tree.Panel', {
    store: store,
    rootVisible: false,
    lines: false,
    useArrows: true,
    listeners: {
        itemclick: function(view, node) {
            if(node.isLeaf()) {
                // some functionality to open the leaf(document) in a tabpanel
            } else if(node.isExpanded()) {
                node.collapse();
            } else {
                node.expand();
            }
        }
    }
});

I've spent some time looking for the same thing. I feel I can definitively answer your question with...
No there isn't a config option for it.
I had to set a click handler. I needed one anyway though to implement functionality for leaf clicks:

var tree = Ext.create('Ext.tree.Panel', {
    store: store,
    rootVisible: false,
    lines: false,
    useArrows: true,
    listeners: {
        itemclick: function(view, node) {
            if(node.isLeaf()) {
                // some functionality to open the leaf(document) in a tabpanel
            } else if(node.isExpanded()) {
                node.collapse();
            } else {
                node.expand();
            }
        }
    }
});
囍孤女 2025-01-13 20:16:38

事实上,您使用了树视图的展开功能。

只需在树面板上实现 itemclick 函数即可:

listeners: {
    itemclick: function (treeview, record, item, index, e, eOpts) {
        treeview.expand(record);
    }
}

In fact you use the expand function of the treeview.

Just implement the itemclick function on you treepanel:

listeners: {
    itemclick: function (treeview, record, item, index, e, eOpts) {
        treeview.expand(record);
    }
}
聆听风音 2025-01-13 20:16:38

如果您使用键盘导航,您可能需要使用 SelectionChange 事件,以便涵盖所有场景,但无论如何,这是我在我的案例中使用的一种方法来实现 singleClick 功能。

在树中定义一个新事件,例如假设您定义了一个从树面板继承的类,那么在“initComponent”中您将创建该事件:

Ext.define('MY.view.CheckList', {
扩展:'Ext.tree.Panel',
别名: 'widget.checklist',

store: 'CheckPoints',
useArrows: true,

initComponent: function () {

    this.callParent(arguments);     
    this.on("selectionchange", this.onSelectionChange);
    this.addEvents({
        singleClick: true 
    });
},

onSelectionChange: function(model, nodes){

    [....]

    // fire statusUpdated event
    this.fireEvent("singleClick", this, model, nodes);
}

});

那么你需要监听你创建的事件,例如:

var mytree = Ext.create("MY.view.CheckList");

mytree.on("singleClick", function( tree, model, Nodes){

console.log(">>>>>>>>>>>>>>>>>>>>> EVENT TRIGGERED <<<<<<<<<<<<<<<<<<<<<<<<");
console.log( tree, model, nodes);
var currSelPath = nodes[0].getPath();

//This will expand the node at the path you just clicked
tree.expandPath(currSelPath);

});

两件事:

  • 你需要稍微调整它以适应你的代码场景
  • Ofc 你可以直接监听“selectionChange”事件并执行此操作,但我认为从代码可重用性的角度来看,它更干净、更明显,如果你添加在触发事件“singleClick”之前进行更多的逻辑和检查,并想象如果您有更多从该基础树继承的树,则只需执行一次。

我确信这不是最完美的解决方案,但就我而言效果很好。

哈!

If you're using keyboard navigation, you probably need to use the selectionChange event so that you cover all the scenarios, but anyway, here's an approach i'm using in my case to achieve the singleClick thingy.

define a new event in the tree, for instance imagine you have defined a class which inherits from the treepanel, then in the "initComponent" you would create the event:

Ext.define('MY.view.CheckList', {
extend: 'Ext.tree.Panel',
alias: 'widget.checklist',

store: 'CheckPoints',
useArrows: true,

initComponent: function () {

    this.callParent(arguments);     
    this.on("selectionchange", this.onSelectionChange);
    this.addEvents({
        singleClick: true 
    });
},

onSelectionChange: function(model, nodes){

    [....]

    // fire statusUpdated event
    this.fireEvent("singleClick", this, model, nodes);
}

});

then you need to listen to the event you created, for instance:

var mytree = Ext.create("MY.view.CheckList");

mytree.on("singleClick", function( tree, model, nodes){

console.log(">>>>>>>>>>>>>>>>>>>>> EVENT TRIGGERED <<<<<<<<<<<<<<<<<<<<<<<<");
console.log( tree, model, nodes);
var currSelPath = nodes[0].getPath();

//This will expand the node at the path you just clicked
tree.expandPath(currSelPath);

});

2 things:

  • You need to tweak it a bit to suit your code scenario
  • Ofc you could just listen to the "selectionChange" event directly and do this, but i think from a code reusability standpopint, its cleaner and more obvious, and if you add a bit more logic and checks before you fire the event "singleClick" and imagine if you have more trees that inherit from this base tree, you just need to do it once.

It's not the most perfect solution, i'm sure, but in my case worked fine.

HTH!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文