コンストラクターから Sencha Touch (2.0) パネルの子クラスに項目を追加しようとしています。以下のコード:
Ext.define("MyApp.view.Icon", {
extend: "Ext.Panel",
config: {
layout: "vbox" //ensures caption appears directly below image
},
constructor: function(cfg) {
this.add(
//First we add the icon image
{
xtype: "image",
src: cfg.src,
width: cfg.width,
height: cfg.height
},
//Then we add the icon caption
{
xtype: "panel",
html: cfg.caption
}
);
return this;
}
});
var anIcon = Ext.create("MyApp.view.Icon", {
src: "http://placehold.it/80",
width: 100,
height: 100,
caption: "My Icon"});
これを行うと、次のエラーが表示されます。
Uncaught TypeError: Cannot call method 'has' of null
に由来するようthis.add()
です。私も試しましたがthis.self.add()
、これもうまくいきません。コンストラクターから要素を挿入する方法はありませんか?