【问题标题】:ExtJS: cannot call method 'getProxy'ExtJS:无法调用方法“getProxy”
【发布时间】:2013-09-06 21:39:47
【问题描述】:

为什么 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'
}

取自docs...

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

【问题讨论】:

  • 控制台是否出现其他错误?如plee提到的语法错误?还是问题中的错字?
  • 是的,这只是一种复制形式
  • 一切正常,你的错误一定是在别的地方fiddle.sencha.com/#fiddle/fb
  • @JuanMendes 我注释掉了storequeryModedisplayField .. 它可以工作。我评论..它坏了。
  • 我们刚刚向您证明了您发布的代码有效,您需要从那开始,而不是仍然说它不起作用。转到我发布的小提琴,看看与您拥有的不同

标签: extjs extjs4


【解决方案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'
    } 
});

【讨论】:

  • 大声笑我只是在一个巨大的小提琴之中。是的,这确实解决了问题 - 我非常感谢您的帮助。话虽如此,我在控制器中的事件处理函数内部执行Ext.create('someView') 之类的操作没有任何问题..
  • @ColinMartell 当您从控制器创建内容时,应用程序已经加载,所以Ext.create 在那里很好。问题是您在定义类时创建了商店。
  • 啊完美!是的,我要投票并标记正确;只是想知道为什么这首先起作用了;)非常感谢
  • 请注意,如果您从initComponent 调用它,则可以使用Ext.create,我只是使用文字来炫耀:)。文字甚至应该在原型中工作,但如果您有多个实例并且可以修改存储,则可能会中断
【解决方案2】:

我认为是因为它在'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'
})

【讨论】:

  • 现在我收到Expecting a function in instanceof check, but got function constructor() 错误..
猜你喜欢
  • 2012-03-09
  • 1970-01-01
  • 1970-01-01
  • 2013-01-01
  • 1970-01-01
  • 2010-12-15
  • 2016-05-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多