【问题标题】:Checkbox in editor grid Extjs编辑器网格 Extjs 中的复选框
【发布时间】:2018-03-03 20:22:04
【问题描述】:

我有这个代码:

{                    
     xtype: 'checkcolumn',
     header: 'Contacto de Emergencia',
     dataIndex: 'contactoEmergencia',
     listeners: {
           beforecheckchange: function() {
                return false;
           }
     },
     width: 60,
     editor: {
         xtype: 'checkbox',
         cls: 'x-grid-checkheader-editor',
         inputValue: 1,
         uncheckedValue: 0                
     }   
}

我希望它发送 1 / 0 而不是 true/false,但它仍在发送 true-false,如何更改它以发送我想要的值?

【问题讨论】:

  • 你能解释一下你想在哪里 1/0 而不是真/假
  • @yajiv 我的意思是,当我将数据发送到数据库时。如果选中则发送 true,未选中则发送 false。我需要更改这些值(真/假)以发送 1 而不是真和 0 而不是假。数据库正在验证它采用 1/0 而不是真/假,因此我无权访问数据库,因此我必须更改这些值
  • 很抱歉,您能否告诉上层对象中的哪个字段正在变为真/假,并且您想将它们更改为 1/0。并给出你如何获得这个真/假值@user9438655的逻辑

标签: javascript checkbox extjs grid boolean


【解决方案1】:

你可以试试下面的代码:-

var store = Ext.create('Ext.data.Store', {
    fields: ['name', 'email', 'phone', 'active'],
    data: [{
        name: 'Lisa',
        email: 'lisa@simpsons.com',
        phone: '555-111-1224',
        active: 1
    }, {
        name: 'Bart',
        email: 'bart@simpsons.com',
        phone: '555-222-1234',
        active: 1
    }, {
        name: 'Homer',
        email: 'homer@simpsons.com',
        phone: '555-222-1244',
        active: 0
    }, {
        name: 'Marge',
        email: 'marge@simpsons.com',
        phone: '555-222-1254',
        active: 1
    }]
});

Ext.create('Ext.grid.Panel', {
    title: 'Simpsons',
    height: 200,
    width: 400,
    renderTo: Ext.getBody(),
    store: store,
    columns: [{
        text: 'Name',
        dataIndex: 'name'
    }, {
        text: 'Email',
        dataIndex: 'email',
        flex: 1
    }, {
        text: 'Phone',
        dataIndex: 'phone'
    }, {
        editor: {
            xtype: 'checkbox',
            cls: 'x-grid-checkheader-editor',
            inputValue: 1,
            uncheckedValue: 0
        },
        text: 'Active',
        dataIndex: 'active',
        renderer: function(value, metadata, record, rowIndex, colIndex, store) {
            var tempVal = '',
                me = this;
            if (value === 1) {
                tempVal = 'checked';
            }
            return "<input name=" + record.get('id') + "_" + record.get('id') + " type='checkbox'" + tempVal + ">";
        }
    }],
    listeners: {
        cellclick: function(grid, td, cellIndex, record, tr, rowIndex, e, eOpts) {
            console.log(e);
            if (e.target.type && e.target.type === 'checkbox') {
                let checkVal = e.target.checked ? 1 : 0;
                record.set('active', checkVal);
                console.log(record);
            }
        }
    }
});

您也可以查看fiddle 在控制台上您可以查看更新的记录。

希望对你有帮助:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-14
    • 2014-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多