Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/465.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在extjs中选中复选框组中的所有复选框?_Javascript_Extjs_Sencha Architect_Extjs4.2 - Fatal编程技术网

Javascript 如何在extjs中选中复选框组中的所有复选框?

Javascript 如何在extjs中选中复选框组中的所有复选框?,javascript,extjs,sencha-architect,extjs4.2,Javascript,Extjs,Sencha Architect,Extjs4.2,我有一个复选框组,其中有许多复选框。当一个按钮点击时,我想检查一下它们。这些复选框是动态创建的 var json = result.responseText; var temp = JSON.parse(json); for(var i=0;i<Object.keys(temp[newValue]).length;i++){ menuArray.push({ xtype: 'checkboxfield',

我有一个复选框组,其中有许多复选框。当一个按钮点击时,我想检查一下它们。这些复选框是动态创建的

var json = result.responseText;
    var temp = JSON.parse(json);

    for(var i=0;i<Object.keys(temp[newValue]).length;i++){           
        menuArray.push({
            xtype: 'checkboxfield',
            boxLabel: (temp[newValue][i]).split("_").join(" "),
            name: temp[newValue][i],
            id:temp[newValue][i],
            inputValue: 'true',
            uncheckedValue: 'false',
            formBind: false
        });
    }

    checkboxGroup = new Ext.form.CheckboxGroup({
        xtype: 'checkboxgroup',
        fieldLabel: '',
        id:'moduleCheckboxGroup',
        columns: 1,
        items: menuArray
    });

    permissionPanel.removeAll();
    permissionPanel.add(checkboxGroup);
var json=result.responseText;
var temp=JSON.parse(JSON);
对于(var i=0;i,您可以使用“query”方法使用“isCheckbox”搜索child


在ExtJS 4.x中,Eldono的解决方案有一个快捷方式:

var checkBoxes = checkboxGroup.getBoxes()

Sencha docs:

我将创建一个按钮,其中包含对复选框组的引用,然后存储状态,以便在单击时切换选择和取消选择。下面是一段实时代码

应用程序 动态检查组 试试这个链接
var checkBoxes = checkboxGroup.getBoxes()
var group = Ext.create('App.DynamicCheckboxGroup', {
    id: 'mycheckboxgroup',
    count : 9,
    columns : 3,
    width: 180,
    renderTo: Ext.getBody()
});

Ext.create('App.CheckboxGroupButton', {
    checkboxGroup: group,
    renderTo: Ext.getBody()
});
Ext.define('App.DynamicCheckboxGroup', {
    extend : 'Ext.form.CheckboxGroup',
    config : {
        count : 3
    },
    initComponent : function() {
        var me = this;
        var items = [];
        for (var i = 1; i <= me.count; i++) {
            items.push({
                xtype: 'checkbox',
                boxLabel: 'Test' + i,
                name: 'test' + i,
                inputValue: 'true',
                uncheckedValue: 'false',
                formBind: false
            });
        }
        me.items = items;
        me.callParent(arguments);
    }
});
Ext.define('App.CheckboxGroupButton', {
    extend: 'Ext.Button',
    config : {
        checkboxGroup : null,
        states : [{
            text : 'Deselect All',
            value : 1
        }, {
            text: 'Select All',
            value : 0
        }]
    },
    initComponent : function() {
        var me = this;
        me.setText(me.states[1].text);
        me.callParent(arguments);
    },
    handler : function (button, e) {
        var me = this;
        var newState = me.states.reduce(function(result, state) {
            return state.text !== button.getText() ? state : result;
        }, {});
        Ext.Array.each(me.checkboxGroup.getBoxes(), function (checkbox) {
            checkbox.setValue(newState.value);
        });
        button.setText(newState.text);
    }
});