简体   繁体   English

ExtJ清除树面板中的复选框

[英]ExtJs clear checkboxes in a tree panel

In a extjs app, I have a tree panel that is loading json data from a store. 在extjs应用程序中,我有一个树面板,该树面板正在从商店加载json数据。 In that information I have a property checked that allows manipulate a checkbox over a row in the tree panel. 在该信息中,我checked了一个属性,该属性允许操纵树面板中一行上的复选框。

How can I do to uncheck graphically the checkbox by listening a button? 如何通过侦听按钮取消图形化的复选框? (Clean all checked boxes) (清除所有复选框)

Here's a fiddle that explain a bit the situation. 这是一个小提琴,可以解释一些情况。

https://fiddle.sencha.com/#fiddle/17v3 https://fiddle.sencha.com/#fiddle/17v3

Update your code like so: 像这样更新您的代码:

Ext.application({
    name: 'Fiddle',

    launch: function() {
        Ext.define('modeloCapa', {
            extend: 'Ext.data.Model',
            fields: ['nombre']
        });

        var treeStore = Ext.create('Ext.data.TreeStore', {
            model: 'modeloCapa',
            proxy: {
                type: 'ajax',
                url: "data1.json",
                reader: {
                    type: 'json',
                    root: 'Result'
                }
            }
        });

        var tree = Ext.create('Ext.tree.Panel', {
            title: 'Test',
            width: 500,
            store: treeStore,
            rootVisible: false,
            renderTo: Ext.getBody(),
            columns: [{
                xtype: 'treecolumn',
                flex: 2,
                sortable: true,
                dataIndex: 'titulo'
            }],tbar: [{
                xtype: 'button',
                 id: 'btnApagarCapas',
                 text : 'Button',
                 width: 100,
                 tooltip: 'Uncheck!!',
                 iconAlign : 'center',
                    listeners: {
                        click : function(){
                            treeStore.suspendEvents();
                            treeStore.getRootNode().cascadeBy(function(node) {
                                if (node.get('checked')) {
                                    node.set('checked', false);
                                }
                            });
                            treeStore.resumeEvents();
                            tree.getView().refresh();
                    }
                }
            }]
        });
    }
});

Loop over all the nodes, uncheck the ones that are checked. 遍历所有节点,取消选中已检查的节点。 The suspend events is to prevent the view from refreshing each node as it is unchecked, just do it in bulk at the end. 挂起事件是为了防止视图在未选中时刷新每个节点,而只是在最后大量进行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM