Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/439.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在显示在Ext.grid.Panel列之前,修改文本字段中的值_Javascript_Extjs - Fatal编程技术网

Javascript 在显示在Ext.grid.Panel列之前,修改文本字段中的值

Javascript 在显示在Ext.grid.Panel列之前,修改文本字段中的值,javascript,extjs,Javascript,Extjs,当我单击Ext.grid.Panel中的列时,我需要修改文本字段中的值,所以我使用了beforeshow listener Ext.create('Ext.data.Store', { storeId:'simpsonsStore', fields:['name', 'email', 'phone'], data:{'items':[ {"name":"Lisa", "email":"lisa@simpsons.com", "phone":"555-111-

当我单击Ext.grid.Panel中的列时,我需要修改文本字段中的值,所以我使用了beforeshow listener

Ext.create('Ext.data.Store', {    storeId:'simpsonsStore',
    fields:['name', 'email', 'phone'],
    data:{'items':[
        {"name":"Lisa", "email":"lisa@simpsons.com", "phone":"555-111-1224"},
        {"name":"Bart", "email":"bart@simpsons.com", "phone":"555-222-1234"},
        {"name":"Homer", "email":"homer@simpsons.com", "phone":"555-222-1244"},
        {"name":"Marge", "email":"marge@simpsons.com", "phone":"555-222-1254"}
    ]},
    proxy: {
        type: 'memory',
        reader: {
            type: 'json',
            rootProperty: 'items'
        }
    }
});


Ext.create('Ext.grid.Panel', {
    title: 'Simpsons',
    store: Ext.data.StoreManager.lookup('simpsonsStore'),
    columns: [
        {header: 'Name',  dataIndex: 'name', editor: 'textfield'},
        {header: 'Email', dataIndex: 'email', flex:1,
            editor: {
                xtype: 'textfield',
                allowBlank: false,
                listeners : {
                    beforeshow : function(obj, event, eOpts) {
                        alert();
                    }
                }
            }
        },
        {header: 'Phone', dataIndex: 'phone'}
    ],
    selModel: 'cellmodel',
    plugins: {
        ptype: 'cellediting',
        clicksToEdit: 1
    },
    height: 200,
    width: 400,
    renderTo: Ext.getBody()
});

但是,当我点击该列时,侦听器没有启动,请在我点击该列时显示在文本字段中之前,告诉我如何修改该值


提前感谢。

如果您想显示与存储的值不同的值,我认为更好的方法是在列中使用a。

如果您想显示与存储的值不同的值,我认为更好的方法是在列中使用a。

只需将侦听器代码从插件移动到网格。 那不是

plugins: {
        ptype: 'cellediting',
        clicksToEdit: 1,
        listeners : {
            beforeedit: function(ed, context){
                var field,
                    column = grid.headerCt.getHeaderAtIndex(context.colIdx);

                if (context.column.dataIndex === 'email') {
                    context.column.field.setValue('ashok');
                    console.log(context.column);
                }    
            }
        }

    },
将侦听器移动到网格。:)


只需将侦听器代码从插件移动到网格。 那不是

plugins: {
        ptype: 'cellediting',
        clicksToEdit: 1,
        listeners : {
            beforeedit: function(ed, context){
                var field,
                    column = grid.headerCt.getHeaderAtIndex(context.colIdx);

                if (context.column.dataIndex === 'email') {
                    context.column.field.setValue('ashok');
                    console.log(context.column);
                }    
            }
        }

    },
将侦听器移动到网格。:)


我收到了Sencha论坛的回复

如果有人感兴趣,请遵循以下代码和链接

Ext.create('Ext.data.Store', {
    storeId:'simpsonsStore',
    fields:['name', 'email', 'phone'],
    data:{'items':[
        {"name":"Lisa", "email":"lisa@simpsons.com", "phone":"555-111-1224"},
        {"name":"Bart", "email":"bart@simpsons.com", "phone":"555-222-1234"},
        {"name":"Homer", "email":"homer@simpsons.com", "phone":"555-222-1244"},
        {"name":"Marge", "email":"marge@simpsons.com", "phone":"555-222-1254"}
    ]},
    proxy: {
        type: 'memory',
        reader: {
            type: 'json',
            rootProperty: 'items'
        }
    }
});

var grid = Ext.create('Ext.grid.Panel', {
    title: 'Simpsons',
    store: Ext.data.StoreManager.lookup('simpsonsStore'),
    columns: [
        {header: 'Name',  dataIndex: 'name', editor: 'textfield'},
        {header: 'Email', dataIndex: 'email', flex:1,
            editor: {
                xtype: 'textfield',
                allowBlank: false
            }
        },
        {header: 'Phone', dataIndex: 'phone'}
    ],
    selModel: 'cellmodel',
    plugins: {
        ptype: 'cellediting',
        clicksToEdit: 1,
        listeners : {
            beforeedit: function(ed, context){
                var field,
                    column = grid.headerCt.getHeaderAtIndex(context.colIdx);

                if (context.column.dataIndex === 'email') {
                    console.log('ashok');
                }    
            }
        }

    },
    height: 200,
    width: 400,
    renderTo: Ext.getBody()
});
小提琴:-


论坛帖子:-

我收到了Sencha论坛的回复

如果有人感兴趣,请遵循以下代码和链接

Ext.create('Ext.data.Store', {
    storeId:'simpsonsStore',
    fields:['name', 'email', 'phone'],
    data:{'items':[
        {"name":"Lisa", "email":"lisa@simpsons.com", "phone":"555-111-1224"},
        {"name":"Bart", "email":"bart@simpsons.com", "phone":"555-222-1234"},
        {"name":"Homer", "email":"homer@simpsons.com", "phone":"555-222-1244"},
        {"name":"Marge", "email":"marge@simpsons.com", "phone":"555-222-1254"}
    ]},
    proxy: {
        type: 'memory',
        reader: {
            type: 'json',
            rootProperty: 'items'
        }
    }
});

var grid = Ext.create('Ext.grid.Panel', {
    title: 'Simpsons',
    store: Ext.data.StoreManager.lookup('simpsonsStore'),
    columns: [
        {header: 'Name',  dataIndex: 'name', editor: 'textfield'},
        {header: 'Email', dataIndex: 'email', flex:1,
            editor: {
                xtype: 'textfield',
                allowBlank: false
            }
        },
        {header: 'Phone', dataIndex: 'phone'}
    ],
    selModel: 'cellmodel',
    plugins: {
        ptype: 'cellediting',
        clicksToEdit: 1,
        listeners : {
            beforeedit: function(ed, context){
                var field,
                    column = grid.headerCt.getHeaderAtIndex(context.colIdx);

                if (context.column.dataIndex === 'email') {
                    console.log('ashok');
                }    
            }
        }

    },
    height: 200,
    width: 400,
    renderTo: Ext.getBody()
});
小提琴:-


论坛帖子:-

谢谢Vick,这是我从Sencha论坛修改的代码:)谢谢Vick,这是我从Sencha论坛修改的代码:)