0

玩弄 Extreact,我的页面上有一个复选框,我想控制它的选中状态。例如,我想在我的状态中设置选中的值,并且能够检查或取消选中该输入,而无需以用户身份单击它。

问题是它CheckboxField只有一个checked指向初始状态的道具,所以之后它就没什么用了。

4

1 回答 1

0

不可能通过框来防止点击改变状态,但通过覆盖很容易实现。小提琴

Ext.define(null, {
    override: 'Ext.field.Checkbox',

    updateReadOnly: function (value, oldValue) {
        this.callParent([value, oldValue]);
        this.inputElement.dom.onclick = value ? function () {
            return false;
        } : null;
    }
})

Ext.application({
    name: 'Fiddle',

    launch: function () {
        Ext.Viewport.add({
            xtype: 'container',
            items: [{
                id: 'foo',
                xtype: 'checkbox',
                readOnly: true
            }, {
                xtype: 'button',
                text: 'On',
                handler: function () {
                    Ext.getCmp('foo').check();
                }
            }, {
                xtype: 'button',
                text: 'Off',
                handler: function () {
                    Ext.getCmp('foo').uncheck();
                }
            }]
        });
    }
});
于 2018-03-20T21:15:46.563 回答