0

为什么这会失败cannot call method 'getProxy' of undefined

{
    name: 'customer_name',
    xtype: 'combobox',
    fieldLabel: 'Customer',
    emptyText: 'ex. Google',
    allowBlank: false,
    queryMode: 'local',
    store: Ext.create('Ext.data.ArrayStore', {
        storeId: 'myStore',
        fields: ['name'],
        data: [ 'google', 'facebook', 'twitter']
    }),
    displayField: 'name'
}

取自文档...

在这段代码中它 100% 失败了。

4

2 回答 2

1

问题很可能是您在对象的原型上定义项目。您不应该这样做,因为这意味着它将被所有实例共享,并且它会在定义类时尝试实例化您的商店,而不是在实例化类时。

代替

Ext.define('my.Panel', {
    items: {
        name: 'customer_name',
        xtype: 'combobox',
        fieldLabel: 'Customer',
        emptyText: 'ex. Google',
        allowBlank: false,
        queryMode: 'local',
        store: Ext.create('Ext.data.ArrayStore', {
            storeId: 'myStore',
            fields: ['name'],
            data: [ 'google', 'facebook', 'twitter']
        }),
        displayField: 'name'
    } 
});

Ext.define('my.Panel', {
    initComponent: function() {
        this.items =  {
            name: 'customer_name',
            xtype: 'combobox',
            fieldLabel: 'Customer',
            emptyText: 'ex. Google',
            allowBlank: false,
            queryMode: 'local',
            store: {
                // Let Ext instantiate the store
                type: 'array',
                // Don't use this, it's an euphemism for a global
                storeId: 'myStore',
                fields: ['name'],
                data: [ 'google', 'facebook', 'twitter']
            },
        displayField: 'name'
    } 
});
于 2013-09-06T22:28:08.753 回答
1

我认为因为它缺少结束引号'name

此代码工作正常

Ext.widget({
    name: 'customer_name',
    xtype: 'combobox',
    fieldLabel: 'Customer',
    emptyText: 'ex. Google',
    allowBlank: false,
    queryMode: 'local',
    store: Ext.create('Ext.data.ArrayStore', {
        storeId: 'myStore',
        fields: ['name'],
        data: [ 'google', 'facebook', 'twitter']
    }),
    displayField: 'name'
})
于 2013-09-06T21:54:22.023 回答