PDA

View Full Version : Unable to call 'listen' method in the Controller



lintonar
13 Aug 2013, 12:44 AM
Hi,

I'm using the version extjs 4.2.2. I am unable to call 'listen' method from the controller. It gives the message "Uncaught TypeError: Cannot call method 'listen' of undefined " in the console of Chrome. On debugging I get the method 'listen' as undefined. I have the latest library specified in the resources. I assume it is referring to the method of extjs 3.x because if I use the method 'control' instead of 'listen' it works fine.

This is the code:

Ext.define('MyApp.controller.MyController', {
extend: 'Ext.app.Controller',


init: function() {
console.log(this);
this.listen({ '[xtype=button]':{
click: function() { alert("clicked")
}
}) ;
}


});

Please help.

Linton

scottmartin
15 Aug 2013, 6:57 AM
You can use the following



init : function () {
var me = this;

me.control({

'myapp-list button[action=doMyAction]' : { // action defined on button in view
click : me.myClickEvent
}

});

},
..


Scott

halcwb
15 Aug 2013, 7:43 AM
You can use the following



init : function () {
var me = this;

me.control({

'myapp-list button[action=doMyAction]' : { // action defined on button in view
click : me.myClickEvent
}

});

},
..


Scott

You can do that, but that is not the problem, the code should be:



Ext.define('MyApp.controller.MyController', {
extend: 'Ext.app.Controller',




init: function () {
console.log(this);
this.listen({
component: {
'[xtype=button]': {
click: function () {
alert("clicked")
}
}}});
}




});


Note that with listen you have to supply the eventdomain, but that's the nice part.

Check out this fiddle

7c

P.s. Please mark as answered if this answers your question.