【问题标题】:In Ext.js changing the value of checkboxgroup在 Ext.js 中改变 checkboxgroup 的值
【发布时间】:2019-01-08 19:58:45
【问题描述】:

我写了以下内容:

{
    xtype: "checkboxgroup",
    fieldLabel: "Content type",
    name: "content_type",
    id: "fx-form-content_type",
    rows: 1,
    value: 0,
    editable: false,
    forceSelection: true,
    queryMode: "local",
    horizontal: true,
    hidden: false,
    listeners: {
        change: function(cmp, value) {

            //console.error(cmp.down("checkbox[inputValue=1]"));
            //console.error(cmp.down("checkbox[inputValue=0]"));

            //var vod_or_npvr = value["content_type_vod_or_npvr"];
            console.error(cmp);
            console.error(value);
            /*
            if(vod_or_npvr === 0)
            {
                Ext.getCmp("fx-form-content_type").setValue(2);
            }

            else if(vod_or_npvr === 1)
            {
                Ext.getCmp("fx-form-content_type").setValue(1);
            }
            else if(vod_or_npvr === [1,0])
            {
                Ext.getCmp("fx-form-content_type").setValue(0);
            }
            else {
                Ext.getCmp("fx-form-content_type").setValue(3);
            }*/

        }
    },
    items: [{
        xtype: "checkboxfield",
        fieldLabel: "VOD",
        checked: false,
        //name      : "content_type_vod_or_npvr",
        inputValue: 1,
        id: "fx-form-content_type-VOD",
        value: 1,
        labelWidth: 40
    }, {
        xtype: "checkboxfield",
        fieldLabel: "NPVR",
        checked: false,
        //name      : "content_type_vod_or_npvr",
        inputValue: 0,
        id: "fx-form-content_type-NPVR",
        value: 2,
        labelWidth: 40
    }]
}

如何更改checboxgroup 的值?

我需要它来让checboxes 两个都枯萎,一个都不枯萎,或者其中一个枯萎。我正在尝试使用更改侦听器和setValue 函数来做到这一点,但它不起作用。 谁能明白怎么做?

【问题讨论】:

    标签: javascript checkbox extjs


    【解决方案1】:

    您可以使用CheckboxGroup.setValue(false) 重置其中的所有项目,或者如果您想重置特定项目,则只需使用CheckboxGroup.down(your item here),然后再次使用.setValue(false)

    您可以在这里查看工作Sencha Fiddle

    代码片段

    Ext.application({
        name: 'Fiddle',
    
        launch: function () {
            Ext.create({
                xtype: 'form',
                title: 'Checkbox Group',
                width: '100%',
    
                bodyPadding: 10,
                renderTo: Ext.getBody(),
                bbar: ['->', {
                    text: 'Reset All',
                    handler: function () {
                        var checkboxgroup = this.up('form').down('checkboxgroup');
                        checkboxgroup.setValue(false)
                    }
                },{
                    text: 'Reset Item 2',
                    handler: function () {
                        var checkboxgroup = this.up('form').down('checkboxgroup');
                        checkboxgroup.down('[inputValue=2]').setValue(false)
                    }
                }],
    
                items: [{
                    xtype: 'checkboxgroup',
                    fieldLabel: 'Two Columns',
                    // Arrange checkboxes into two columns, distributed vertically
                    columns: 2,
                    vertical: true,
                    items: [{
                        boxLabel: 'Item 1',
                        name: 'rb',
                        inputValue: '1'
                    }, {
                        boxLabel: 'Item 2',
                        name: 'rb',
                        inputValue: '2',
                        checked: true
                    }, {
                        boxLabel: 'Item 3',
                        name: 'rb',
                        inputValue: '3'
                    }, {
                        boxLabel: 'Item 4',
                        name: 'rb',
                        inputValue: '4'
                    }, {
                        boxLabel: 'Item 5',
                        name: 'rb',
                        inputValue: '5'
                    }, {
                        boxLabel: 'Item 6',
                        name: 'rb',
                        inputValue: '6'
                    }]
                }]
            });
        }
    });
    

    【讨论】:

    • 如果我在我的应用程序中执行 cmp.setValue(val) 会引发错误,或者不会更改任何内容。那我该怎么办呢?
    • 尝试调试代码检查是否有可用的方法
    • 我收到此错误:无法使用 'in' 运算符在 2 中搜索 'VOD' 它有一个 setValue() 方法,但由于某种原因它正在做一些奇怪的事情知道为什么会发生吗?跨度>
    猜你喜欢
    • 1970-01-01
    • 2015-02-09
    • 2017-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-08
    • 2013-11-22
    相关资源
    最近更新 更多