PDA

View Full Version : Uncaught TypeError: Object #<Object> has no method 'addCls'



kashim
29 Dec 2011, 5:11 AM
Hi

I am looking at the layout browser demo and trying to change things around a bit (for my understanding)

Basically, during a tree node click, I am adding the tabnestedlayout component to my main contentPanel. However nothing its not showing. When I try to call setActiveItem I get the error - Uncaught TypeError: Object #<Object> has no method 'addCls'

Any ideas please



var contentPanel = {
id: 'content-panel',
region: 'center',
layout: 'card',
};


treePanel.getSelectionModel().on('select', function (selModel, record) {
if (record.get('leaf')) {
var mytab;
Ext.Object.each(getCombinationLayouts(), function (name, example) {
mytab = example;
});
Ext.getCmp('content-panel').items.add(mytab.id, mytab);
Ext.getCmp('content-panel').layout.setActiveItem(0); //this line is a problem


}
}
});

Farish
29 Dec 2011, 5:24 AM
From the API docs:



p = Ext.create('Ext.panel.Panel', {
layout: 'card',
items: [
{ html: 'Card 1' },
{ html: 'Card 2' }
],
renderTo: Ext.getBody()
});
p.getLayout().setActiveItem(1);

You need to create a panel.

Regards,
Farish

kashim
29 Dec 2011, 7:18 AM
Thanks

Out of interest, why does it work when the the layout examples are created first. All I was trying to was create the layout when the tree node was clicked.

Code in demo example -
var layoutExamples = [];
Ext.Object.each(getBasicLayouts(), function(name, example) { layoutExamples.push(example);});
var contentPanel = { items: layoutExamples, ..
thankskashim

kashim
29 Dec 2011, 7:20 AM
Sorry Farish, (I wanted to mark your answer as the best answer...but I clicked the wrong link)

Farish
29 Dec 2011, 7:44 AM
Ext.getCmp('content-panel').layout.setActiveItem(0);

In this line, you are trying to access the layout of the item with id 'content-panel' but you have not defined anywhere that this item is of type panel. Creating a panel using Ext.create tells the framework that this is a panel object (which has a layout).

Could you post a link to the example you are referring to?

kashim
30 Dec 2011, 12:10 AM
http://dev.sencha.com/deploy/ext-4.0.7-gpl/examples/layout-browser/layout-browser.html

(http://dev.sencha.com/deploy/ext-4.0.7-gpl/examples/layout-browser/layout-browser.html)

Farish
30 Dec 2011, 12:28 AM
I couldn't find the code which you had mentioned in your comment on the examples page. In fact, I couldn't see any complete could there. There were just bits of code. Any way, if you use the create() function, then it should work.

kashim
30 Dec 2011, 12:32 AM
Don't worry. I'm still a newbie. I am learning something new everyday.

regards
kashim