繁体   English   中英

错误:无法调用未定义的方法“ createChild”

[英]Error: Cannot call method 'createChild' of undefined

我写了这样定义的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,一切正常。

您可以在此处查看并运行此示例http://jsfiddle.net/C3HEu/12/

您需要所有的Ext代码才能在Ext.onReady()运行。 http://jsfiddle.net/C3HEu/22/

或者,使Ext在浏览器的onDomReady事件中运行,而不是在onLoad http://jsfiddle.net/C3HEu/24/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM