获取错误为getEditor undefined

时间:2017-02-27 12:52:38

标签: extjs combobox

我试图使用下面的网格获取单元格的值。实际上我只是想在控制台中打印它

console.log(Ext.ComponentQuery.query('gridcolumn[itemId=gridId]')[0].getEditor().getStore().findRecord('description', 'Description'));

网格代码

Ext.define('Examples.grid.fdGrid', {
    extend: 'Ext.grid.Panel',

    xtype: foodGrid',
    forceNewStore: true,
    itemId: 'foodGrid',
    height: Ext.getBody().getViewSize().height - 200,
    autoload: false,
    columns: [
    {
            text: 'Food Distrib',
            xtype: 'gridcolumn',
            itemId:'gridId', 
            dataIndex: 'food_distributor',
            flex: 1,
            renderer: function(value){
            if(Ext.isNumber(value)){
                var store = this.getEditor().getStore();
                return store.findRecord('foodid',value).get('description');
            }
            return value;
            },
            editor: {
                xtype: 'combobox',
                allowBlank: true,
                displayField: "description",
                valueField: "foodid",                      
                listeners: {

                    expand: function () {
                        var call = this.up('foodgrid[itemId=foodGrid]').getSelectionModel().selection.record.data.networkname.trim();
                        this.store.clearFilter();
                        this.store.filter({
                            property: 'call',
                            value: call,
                            exactMatch: true
                        })
                    }
                },

            },
        }
        });

但我收到的错误为Uncaught TypeError: Cannot read property 'getEditor' of undefined

错误是什么?

添加了网格代码部分,以及我想要打印其值的列。

3 个答案:

答案 0 :(得分:0)

在需要时(第一次编辑时)创建编辑器。因此,首次调用渲染器时,编辑器尚不可用。

您想要在渲染器内执行的操作是直接访问商店,而不是通过编辑器。然后,您只需要预先加载的商店即可正确渲染网格。

System.IO.Compression.FileSystem.dll

当然,在渲染网格之前,必须确保已加载string startPath = @"c:\example\start"; string zipPath = @"c:\example\result.zip"; string extractPath = @"c:\example\extract"; ZipFile.CreateFromDirectory(startPath, zipPath); ZipFile.ExtractToDirectory(zipPath, extractPath); The directories within the variables don't exist but that doesn't matter because ZipFile isn't even being found.

答案 1 :(得分:0)

你有吗

var cellEditing = Ext.create('Ext.grid.plugin.CellEditing', {
              clicksToEdit: 1
});

没有插件,编辑器就无法工作!当你试图获得它时,编辑器将是未定义的

答案 2 :(得分:0)

人们只能猜到你想要做的事情,但是:

  • Column没有自己的选择模型。 Grid确实如此。
  • Combobox需要商店。
  • 如果设置了编辑器且列为getEditor ,则
  • String可能会返回Objecteditable
  • editable由网格插件提供。换句话说,将列指定为可编辑并指定列编辑器是不够的,您还需要为网格提供可编辑的插件。

一些工作示例:

Ext.define('Examples.grid.fdGrid', {
extend: 'Ext.grid.Panel',

xtype: 'feedGrid',
forceNewStore: true,
itemId: 'foodGrid',
height: Ext.getBody().getViewSize().height - 200,
autoload: false,
 selModel: 'cellmodel',
plugins: {
    ptype: 'cellediting',
    clicksToEdit: 1
},
columns: [
{
        text: 'Food Distrib',
        xtype: 'gridcolumn',
        itemId:'gridId', 
        dataIndex: 'food_distributor',
        flex: 1,
        editable: true,
        renderer: function(value){
        if(Ext.isNumber(value)){
            var store = this.getEditor().getStore();
            return store.findRecord('foodid',value).get('description');
        }
        return value;
        },

        editor: {
            xtype: 'combobox',
            allowBlank: true,
            displayField: "description",
            valueField: "foodid",    
            store: {
                fields:['food_distributor', 'description'],
                data:[
                    {
                        'food_distributor':'a',
                        foodid:1,
                        description:'aaaaa'
                    },
                    {
                        'food_distributor':'a',
                        foodid:2,
                        description:'bbbbbb'
                    },
                    {
                        'food_distributor':'a',
                        foodid:3,
                        description:'aaaaa'
                    }]
            },
            listeners: {
                expand: function () {
                    debugger;
                    var desc = this.up('grid').getSelectionModel().getSelection()[0].get('description').trim();
                    this.store.clearFilter();
                    this.store.filter({
                        property: 'description',
                        value: desc,
                        exactMatch: true
                    })
                }
            },

        },
    }
    ]
});

Ext.create('Examples.grid.fdGrid', {
    store: {
        fields:['food_distributor', 'description'],
        data:[
            {
                'food_distributor':'a',
                foodid:1,
                description:'aaaaa'
            },
            {
                'food_distributor':'a',
                foodid:2,
                description:'bbbbbb'
            },
            {
                'food_distributor':'a',
                foodid:3,
                description:'aaaaa'
            }]
    },
    renderTo:Ext.getBody()
})