如何取消选中Ext.tree.TreePanel中的所有树节点?

发布于 2024-10-07 13:40:57 字数 52 浏览 3 评论 0原文

我想要一个“重置”方法来取消选中 Ext.tree.TreePanel 中的所有选中节点。

I would like a 'reset' method to uncheck all the checked nodes in Ext.tree.TreePanel.

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

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

发布评论

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

评论(4

寻找我们的幸福 2024-10-14 13:40:57
tree.getRootNode().cascade(function(n) {
    var ui = n.getUI();
    ui.toggleCheck(false);
});

正如在这里找到的:
http:// /www.sencha.com/forum/showthread.php?12888-solved-programatically-unchecking-checked-tree-nodes&p=62845#post62845

tree.getRootNode().cascade(function(n) {
    var ui = n.getUI();
    ui.toggleCheck(false);
});

As found here:
http://www.sencha.com/forum/showthread.php?12888-solved-programatically-unchecking-checked-tree-nodes&p=62845#post62845

执手闯天涯 2024-10-14 13:40:57

我找到了如下方法,但似乎“casecade”方法效果不佳,我需要多次调用“reset”来取消选中所有选中的子项:

reset: function (){
            startNode = this.root;
            var f = function () {
                if (this.attributes.checked) {
                    this.attributes.checked = false;
                    this.getUI().toggleCheck(false);
                }
            };
            startNode.cascade(f);
        }

I found a method as below, but seems the 'casecade' method do not worked well, I need call 'reset' several times to unchecked all the checked children:

reset: function (){
            startNode = this.root;
            var f = function () {
                if (this.attributes.checked) {
                    this.attributes.checked = false;
                    this.getUI().toggleCheck(false);
                }
            };
            startNode.cascade(f);
        }
云胡 2024-10-14 13:40:57

我无法获得使用 Extjs 4.0.7 的其他答案。此外,使用“级联”方法会发出警告,表明该方法已被弃用。它建议使用“cascadeBy”代替。除了方法名称之外,我无法找到方法签名的差异(相同的参数,this,行为)。

但是,我找到了这段有效的代码:

{ 
    xtype: 'button', 
    text: 'Deselect All',
    listeners:{
        click: function(){

            var tree = Ext.ComponentQuery.query( 'treepanel[itemId=user_flags_tree]')[0];
            tree.getRootNode().cascadeBy(function(){

                this.set( 'checked', false );

            });

        }
    }
}

感谢这篇文章:
http://www .sencha.com/forum/showthread.php?149627-Programmaticaly-check-uncheck-checkboxes-in-the-Tree-panel

I was unable to get either of the other answers to work with Extjs 4.0.7. Also, the use of the "cascade" method issued a warning that it's deprecated. It recommended using "cascadeBy" instead. Other than the method name, I was unable to find a difference in the method signature (same arguments, this, behaviour).

However, I was able to find this code that worked:

{ 
    xtype: 'button', 
    text: 'Deselect All',
    listeners:{
        click: function(){

            var tree = Ext.ComponentQuery.query( 'treepanel[itemId=user_flags_tree]')[0];
            tree.getRootNode().cascadeBy(function(){

                this.set( 'checked', false );

            });

        }
    }
}

Thanks to this post:
http://www.sencha.com/forum/showthread.php?149627-Programmaticaly-check-uncheck-checkboxes-in-the-Tree-panel

欲拥i 2024-10-14 13:40:57
var nodes = treePanel.getView().getNodes();
var records = treePanel.getView().getRecords(nodes);
for (var i = 0; i < records.length; i++) {
    records[i].set('checked',true);
}
var nodes = treePanel.getView().getNodes();
var records = treePanel.getView().getRecords(nodes);
for (var i = 0; i < records.length; i++) {
    records[i].set('checked',true);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文