为什么渲染不能在xtype中工作

时间:2015-01-14 19:53:55

标签: extjs

简单代码:

var myPanel = {
    xtype : 'panel',
    height : 100,
    width : 100,
    html : 'Hello!',
    renderTo:Ext.getBody()
};

为什么renderTo在xtype中不起作用? 但是这段代码有效:

Ext.define('MyApp.CustomClass', {
    extend: 'Ext.panel.Panel',
    alias: 'widget.myCustomComponent'
});

new Ext.Panel({
    renderTo:Ext.getBody(),
    items : [{
        xtype : 'myCustomComponent',
        html:'World'
    }]
});

1 个答案:

答案 0 :(得分:3)

在下面你没有初始化面板,你需要调用它/将它传递给ExtJs来解析和初始化类。这部分代码只是一个Javascript对象,ExtJs不知道它。

var myPanel = {
    xtype: 'panel',
    height: 100,
    width: 100,
    html: 'Hello!',
    renderTo: Ext.getBody()
};

因此,要使用ExtJs初始化它,您需要使用Ext.create调用,如下所示。

var myPanel = {
    xtype: 'panel',
    height: 100,
    width: 100,
    html: 'Hello!',
    renderTo: Ext.getBody()
};

Ext.create(myPanel);

此处还有一个fiddle演示

相关问题