我编写了这样定义的 ExtJS4 类:
Ext.define('Ext.ux.PictureBox', {
extend: 'Ext.panel.Panel',
alias: 'widget.picturebox',
url: "",
afterRender: function () {
this.callParent();
this.imageEl = Ext.DomHelper.append(this.body, Ext.String.format("<img style='width:{0}px;height:{1}px' src='{2}' />", this.width, this.height, this.url), true);
this.items.items[0].addCls('browse-picture-button');
this.items.items[1].addCls('remove-picture-button');
},
initComponent: function() {
var conf = {
items:[
{
itemid: 'browseBtn',
xtype: 'fileuploadfield',
name: 'photo',
buttonText: '...',
buttonOnly: true,
text: '...',
width: 30,
height: 20
},
{
itemid: 'removeBtn',
xtype: 'button',
text: 'X',
width: 30,
height: 20
}
]
};
Ext.apply(this, Ext.apply(this.initialConfig, conf));
this.callParent(arguments);
},
setSize: function (w, h) {
this.callParent();
if (this.imageEl) {
this.imageEl.setSize(w, h);
}
},
setUrl: function (url) {
this.url = url;
if (this.rendered) {
this.imageEl.dom.src = url;
}
}
});
然后,我创建了这个类:
Ext.create('Ext.ux.PictureBox', {
width: 300,
height: 300,
url: 'http://blogs-images.forbes.com/daviddisalvo/files/2012/01/googlelogo2.jpg',
renderTo: Ext.getBody()
});
并且脚本抛出错误无法调用未定义的方法“createChild”。为什么 ?
如果我使用 'button 而不是 fileuploadfield; 一切正常;
Yuo 可以在此处查看并运行此示例http://jsfiddle.net/C3HEu/12/