Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/432.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 错误:无法调用未定义的方法“createChild”_Javascript_Browser_Extjs - Fatal编程技术网

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

Javascript 错误:无法调用未定义的方法“createChild”,javascript,browser,extjs,Javascript,Browser,Extjs,我编写了如下定义的ExtJS4类: Ext.define('Ext.ux.PictureBox', { extend: 'Ext.panel.Panel', alias: 'widget.picturebox', url: "", afterRender: function () { this.callParent(); this.imageEl = Ext.D

我编写了如下定义的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;
        }
    }
});
脚本抛出错误,无法调用未定义的方法“createChild”。为什么?

如果我使用'按钮而不是fileuploadfield,一切正常


您可以在这里查看并运行此示例

您需要所有的Ext代码在Ext.onReady中运行

或者,让Ext在浏览器的onDomReady事件中运行,而不是onLoad

Ext.create('Ext.ux.PictureBox', {   
    width: 300,
    height: 300,       
    url: 'http://blogs-images.forbes.com/daviddisalvo/files/2012/01/googlelogo2.jpg',
    renderTo: Ext.getBody()
});​