简体   繁体   English

我在使用Ext.define时遇到问题

[英]I have a problem when I use Ext.define

I get the error: 我得到错误:

events is null or not a object

Does anyone know what the problem might be? 有谁知道可能是什么问题?

Ext.onReady(function() {
    Ext.define("com.yx.DflCombo", {
        extend: "Ext.form.field.ComboBox",
        config: {
            name: "dfl",
            fieldLabel: "category"
        },
        constructor: function(config) {
            this.initConfig(config);
            return this;
        }
    });
    Ext.create('Ext.form.Panel', {
        renderTo: Ext.getBody(),
        title: 'Simple Form',
        bodyPadding: 5,
        width: 350,
        items: [Ext.create("com.yx.DflCombo",{})]
    });
});

Thanks, Molecule Man! 谢谢,分子人! I try another test like this. 我尝试这样的另一个测试。

Ext.define("com.yx.MyPanel", {
extend: "Ext.panel.Panel",
config: {
title: "Clannad"
},
constructor: function(config) {
this.initConfig(config);
this.callParent([config]);
}
});
Ext.create("Ext.panel.Panel", {
renderTo: Ext.getBody(),
width: 400,
height: 400,
title: "Key",
items: [Ext.create("com.yx.MyPanel", {})]
});

And I get the error:dockedItems is null or not a object! 我收到错误:dockedItems为null或不是对象! I just want to know when I define a class that extend an EXTJS class, what should I do? 我只想知道在定义扩展EXTJS类的类时该怎么办?

You have two mistakes in your code: 您的代码中有两个错误:

  1. You don't call callParent method in your constructor. 您不要在构造函数中调用callParent方法。 It's required when you are extending existing class: 扩展现有类时,这是必需的:

     constructor: function(config) { this.initConfig(config); this.callParent([config]); } 
  2. The store config should be specified in combobox' config: store配置应在组合框的配置中指定:

     items: [Ext.create("com.yx.DflCombo",{ store: ['item1', 'item2', 'item3'] })] 

Here is demo . 这是演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM