PDA

View Full Version : Error calling container item methods



ricardoz
27 Feb 2012, 1:19 PM
Hi everybody,
I'm having some issues to call methods from container items.
I received the error 'Uncaught TypeError: Object [object Object] has no method 'getSelectionCount'' in Engine.js
Partial code below.
Thanks
(sorry my poor english)

Engine.js:


Ext.define('PC.view.Engine', {
extend: 'Ext.panel.Panel',
alias: 'widget.engine',
requires: [ 'PC.view.AmigosSelector' ],
...
items: [{
xtype: 'container',
width: 500,
layout: {
type: 'vbox',
align: 'stretch'
},
items:[{
xtype: 'amigos_selector',
itemId: 'as1',
flex:1,
title: '1. Escolha um(a) amigo(a)',
genero: 'H'
}]
}],
testMethod: function(){ console.log(this.down('#as1').down('amigos_browser').getSelectionCount());
}
....

AmigosSelector.js:


Ext.define('PC.view.AmigosSelector', { extend: 'Ext.panel.Panel',
...
requires: [ 'PC.view.AmigosBrowser' ],
alias: 'widget.amigos_selector',
autoScroll: true,
layout:'fit',
initComponent: function() {
this.items = [{ xtype: 'amigos_browser' }];
...

ricardoz
27 Feb 2012, 2:25 PM
The error occured in Engine.js at '
console.log(this.down('#as1').down('amigos_browser').getSelectionCount());'

vietits
27 Feb 2012, 3:48 PM
1. What is 'amigos_browser'?
2. In case you have only one 'amigos_browser' component you can use console.log(this.down('amigos_browser').getSelectionCount())

ricardoz
28 Feb 2012, 3:35 AM
Hi Vietits,

AmigosBrowser (alias: 'widget.amigos_browser') is a Ext.view.View.
I have two of it. One in #as1 and another in #as2.

I call the 'testMethod' in a Controller that uses the Engine view:


...
var view = this.getView('Engine').create();
view.testMethod();
...

Thanks

vietits
28 Feb 2012, 5:15 AM
Then I think your code is right. Just track down to see what really is with this code:


console.log(this.down('#as1').down('amigos_browser'));

ricardoz
28 Feb 2012, 8:55 AM
I explored de source and noticed that this method is deprecated (version 4.07).
The correct command is 'console.log(this.down('#as1').down('amigos_browser').getSelectionModel().getSelection());'

'getSelectionModel' returns a 'DataViewModel' object (not documented).
The 'DataViewModel' class extends 'Ext.selection.Model' and the latter has a getSelection method.

Thanks