将图标添加到Sencha中的面板

时间:2012-06-05 14:07:02

标签: icons extjs

我是sencha的新手。我正在尝试向面板添加图标,但我的代码不起作用。

   Ext.define('components.ImagePanel', {
    extend: 'Ext.Panel',    
    initialize: function () {
        this.callParent(arguments);
        var image = {
            xtype: "image",
            src: 'icon.png',
            width:100,
            height:100
                }, 
            scope: this
        };
 this.add([image]);
});

我做错了什么?

1 个答案:

答案 0 :(得分:0)

哇,甚至不知道有一个图像xtype。

无论如何......

要使用xtype,您需要使用Ext.widget();

创建它

所以你的代码应该是这样的:

Ext.define('components.ImagePanel', {
extend: 'Ext.Panel',    
initialize: function () {
    this.callParent(arguments);
    var image = Ext.widget('image',{
        xtype: "image",
        src: 'icon.png',
        width:100,
        height:100
    });
    this.add([image]);
};
});