开发者

How to uncheck all tree nodes in Ext.tree.TreePanel?

I would like a 'reset' method to uncheck all the check开发者_Go百科ed nodes in Ext.tree.TreePanel.


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


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


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


var nodes = treePanel.getView().getNodes();
var records = treePanel.getView().getRecords(nodes);
for (var i = 0; i < records.length; i++) {
    records[i].set('checked',true);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜