是/否到Y / N Ex

问题描述 投票:0回答:1

我想改变从default发送的checkbox值。我有这个代码:

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

我也设置了我的模型:

{
    name: 'contactoEmergencia',
    mapping: 'CONTACTO_EMERGENCIA',
    convert: function(v) {
        return v === 'Y';
    },
    serialize: function(v) {
        return v ? 'Y' : 'N';
    }
},

但它不起作用。默认值true/false不会更改为Y/N

谁知道为什么不改变?我做错了什么?

javascript checkbox extjs boolean
1个回答
0
投票

您可以尝试使用以下代码段: -

var store = Ext.create('Ext.data.Store', {
    fields: ['name', 'email', 'phone', 'active'],
    data: [{
        name: 'Lisa',
        email: '[email protected]',
        phone: '555-111-1224',
        active: 'Y'
    }, {
        name: 'Bart',
        email: '[email protected]',
        phone: '555-222-1234',
        active: 'Y'
    }, {
        name: 'Homer',
        email: '[email protected]',
        phone: '555-222-1244',
        active: 'N'
    }, {
        name: 'Marge',
        email: '[email protected]',
        phone: '555-222-1254',
        active: 'Y'
    }]
});

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 === 'Y') {
                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 ? 'Y' : 'N';
                record.set('active', checkVal);
                console.log(record);
            }
        }
    }
});

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

希望它有帮助:)

© www.soinside.com 2019 - 2024. All rights reserved.