注册xtype时出现问题

时间:2011-06-27 06:01:29

标签: extjs extjs3

我正在尝试按照factory-functions-in-ext-extensions创建工厂函数, 下面是我的代码

Ext.ns('MyApp');

MyApp.SubmitButton = Ext.extend(Ext.Button, {
     text:'Submit'
    ,iconCls:'icon-disk'
    ,initComponent:function() {
        MyApp.SubmitButton.superclass.initComponent.apply(this, arguments);
    } // eo function initComponent
}); // eo extend



var btn = new MyApp.SubmitButton();
Ext.reg('submitbutton1',btn);//this is not working

Ext.reg('submitbutton', MyApp.SubmitButton );//this works

var win1;
if(!win1) {
        win1 = new Ext.Window({
            title       : 'title',
            closeAction : 'hide',
            autoHeight  : true,
            autoWidth   : true,
            height      :  300,
            width       : 500,
            items       : [{xtype:'submitbutton1',id:'submitbutton'}]
        });
    }
win1.show();

当我运行它时抛出错误“b [d.xtype || e]不是构造函数”

1 个答案:

答案 0 :(得分:2)

您不能使用类的实例来注册xtype。你必须使用它的类名。 Ext不会跟踪您正在创建的实例,只需注册自定义组件类 - 这样您就可以使用这种方式:

var button = new MyApp.SubmitButton({
         id : 'submitbutton'
    });

OR,

{
     xtype : 'submitbutton',
     id:'submitbutton'
}

两者都是一样的。查看Saki的this article了解更多信息。

相关问题