1. #1
    Sencha User
    Join Date
    Feb 2008
    Location
    @bryanzarzuela
    Posts
    55
    Vote Rating
    0
    bzarzuela is on a distinguished road

      0  

    Default this.items.add is not a function

    Can anyone tell me why Example 1 works and not Example 2?

    Example 1:
    Code:
    QMT.lazytest = new Ext.extend(Ext.Panel,{
    	title: 'Concern Type', 
    	
    	initComponent: function(){
    		QMT.lazytest.superclass.initComponent.apply(this, arguments);
    	},
    	onRender: function() {
    		QMT.lazytest.superclass.onRender.apply(this, arguments);
    	}
    });

    Example 2:
    Code:
    QMT.lazytest = new Ext.extend(Ext.Panel,{
    	title: 'Concern Type', 
    	items : [
    		{
    			xtype	    : 'form',
    			defaultType : 'datefield',
    			url			: '/reports/concern-type',
    			frame		: true,
    			items       : [
    				{
    					fieldLabel : 'Start Date',
    					name	   : 'start_date'
    				},
    				{
    					fieldLabel : 'End Date',
    					name	   : 'end_date'
    				}
    			],
    			buttons : [
    				{
    					text    : 'Submit',
    					handler : function() {
    						// Is this the best way to handle submits?
    						// Or could I wrap this up in a pre-configured class?
    						this.ownerCt.getForm().submit();
    					}
    				}
    			]
    		}
    	],
    	initComponent: function(){
    		QMT.lazytest.superclass.initComponent.apply(this, arguments);
    	},
    	onRender: function() {
    		QMT.lazytest.superclass.onRender.apply(this, arguments);
    	}
    });
    Both examples are being called by:

    Code:
    Ext.onReady(function() {
       new QMT.lazytest;
    });
    Here's the error example 2 generates in Firebug:
    Code:
    this.items.add is not a function
    add()(Object xtype=form defaultType=datefield)ext-all-debug.js (line 14558)
    initComponent()()ext-all-debug.js (line 14484)
    initComponent()()ext-all-debug.js (line 16385)
    initComponent()()application.js (line 55)
    Component()(Object)ext-all-debug.js (line 12735)
    apply()()ext-base.js (line 9)
    apply()()ext-base.js (line 9)
    apply()()ext-base.js (line 9)
    apply()()ext-base.js (line 9)
    (?)()()application.js (line 19)
    (?)()()ext-all-debug.js (line 1431)
    [Break on this error] this.items.add(c);
    This is driving me nuts. I don't understand why including items would result in this error.

  2. #2
    Sencha User
    Join Date
    Feb 2008
    Location
    @bryanzarzuela
    Posts
    55
    Vote Rating
    0
    bzarzuela is on a distinguished road

      0  

    Default

    I'm an . Searching through the forums, found a thread that said if you want to include items, do it this way:

    QMT.lazytest = new Ext.extend(Ext.Panel,{
    initComponent: function(){
    var config = {
    title: 'Concern Type',
    items : [
    {
    xtype : 'form',
    defaultType : 'datefield',
    url : '/reports/concern-type',
    frame : true,
    items : [
    {
    fieldLabel : 'Start Date',
    name : 'start_date'
    },
    {
    fieldLabel : 'End Date',
    name : 'end_date'
    }
    ],
    buttons : [
    {
    text : 'Submit',
    handler : function() {
    // Is this the best way to handle submits?
    // Or could I wrap this up in a pre-configured class?
    this.ownerCt.getForm().submit();
    }
    }
    ]
    }
    ],
    }
    Ext.apply(this, Ext.apply(this.initialConfig, config));
    QMT.lazytest.superclass.initComponent.apply(this, arguments);
    },
    onRender:function() {
    QMT.lazytest.superclass.onRender.apply(this, arguments);
    }
    });

    Hope this helps someone else.

  3. #3
    Ext User
    Join Date
    Jul 2007
    Location
    Florida
    Posts
    9,996
    Vote Rating
    8
    mjlecomte will become famous soon enough mjlecomte will become famous soon enough

      0  

    Default

    Suggest you look here:
    http://extjs.com/learn/Ext_Forum_Hel..._code_properly

    I didn't bother to examine your code in 2 threads now because of that.

  4. #4
    Ext JS Premium Member SebTardif's Avatar
    Join Date
    Feb 2011
    Location
    Cambridge, MA
    Posts
    1,018
    Vote Rating
    92
    SebTardif is just really nice SebTardif is just really nice SebTardif is just really nice SebTardif is just really nice

      0  

    Default

    I think both ways should work. You just prove that Ext JS is more difficult to use than it could.

Thread Participants: 2