如何在更改时保存按钮

时间:2017-11-02 12:37:57

标签: javascript user-interface extjs3

要在extjs中启用或禁用保存按钮,我做了一个简单的例子:

var panelData = [first = 'true', second = "false"]
TestFormPanel = new Ext.form.FormPanel({
    title: 'TestPanel',
    data: panelData,

    buttons: [
        new Ext.Button({
            id: 'saveButton',
            text: 'save',
            scope: this,
            disabled: true,
            handler: function () {
                panelData = this.getForm().getValues();
                console.log(panelData);
            }
        })],
    defaults: {
        xtype: 'checkbox',
        listeners: [{
            check: function () {
                console.log('check');
                this.saveButton.enable();
            }
        }]
    },
    items: [
        {
            name: 'first',
            fieldLabel: 'first box'

        },
        {
            name: 'second',
            fieldLabel: 'second box'
        }
    ]
});

Ext.onReady(function () {
    console.log('started');
    TestFormPanel.render(document.body)
})

永远不会触发 check 事件。我尝试了许多其他听众,例如点击容器点击选择没有被触发。 我可以在复选框中检测到更改吗?

1 个答案:

答案 0 :(得分:1)

我认为问题是,该字段没有检查事件。 尝试使用更改事件。我认为,数组符号是明确的 http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.form.field.Checkbox-event-change 它应该是:

listeners: {
        change: function () {
            console.log('change event');
        }
    }