Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem is that the 'this' keyword in your second event listener is not set correctly. </p> <p>Your button event listener works correctly because by using the 'handler' property to register the listener ExtJs binds the function automatically to the current button object.</p> <p>This is what the docs say about <code>Ext.button.Button#scope</code>:</p> <blockquote> <p>scope : Object The scope (this reference) in which the handler and toggleHandler is executed. Defaults to this Button.</p> </blockquote> <p>However, when registering listeners using the 'listener' property one has to specify the 'scope' property otherwise the 'this' reference points to the global window object.</p> <p>See <a href="http://docs.sencha.com/ext-js/4-1/#!/api/Ext.util.Observable-method-addListener" rel="nofollow">the docs for the listener property</a></p> <p>In your case the best approach might be to register the listener like this:</p> <pre><code>this.campaignsComboBox = Ext.create('Ext.form.field.ComboBox', { .. }); this.campaignComboBox.on( 'select', function() { this.fireEvent('testEvent'); }, /* 'scope' aka 'this' reference: */ this.campaignsComboBox); </code></pre> <p><strong>UPDATE</strong></p> <p>Here is a working jsfiddle: <a href="http://jsfiddle.net/nXSAN/" rel="nofollow">http://jsfiddle.net/nXSAN/</a></p> <p>Another way to get the correct reference in your listener is to make use of the first function parameter, which is actually a reference to the ComboBox object (in case of the <code>select</code> event):</p> <pre><code> function(cmp) { cmp.fireEvent('testEvent'); } </code></pre> <p><strong>UPDATE2</strong> Sencha (or my provider) is having troubles with Sencha's CDN, so here an 'offline' version.</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;title&gt;Extjs&lt;/title&gt; &lt;link rel="stylesheet" type="text/css" href="extjs-4.1.1/resources/css/ext-all.css"/&gt; &lt;script type="text/javascript" src="extjs-4.1.1/ext-all.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; Ext.define('App.view.prospects.Filter', { alias: 'widget.prospectsfilter', extend: 'Ext.form.Panel', itemId: 'prospectsfilter', height: 50, width: 100, layout: 'fit', initComponent: function() { this.combo = Ext.create('Ext.form.field.ComboBox', { itemId: 'campaignsComboBox', text: 'Test', queryMode: 'local', displayField: 'name', valueField: 'name', store: Ext.create('Ext.data.ArrayStore', { fields: ['name'], data: [ ['entry1'], ['entry2'], ['entry3'] ] }), listeners: { select: function() { this.fireEvent('testEvent') } } }); this.items = [ this.combo ]; this.callParent(arguments); } }); Ext.define('App.controller.ProspectsFilter', { extend: 'Ext.app.Controller', init: function() { this.control({ 'prospectsfilter #campaignsComboBox': { 'testEvent': function() { console.log('Found #campaignsComboBox!'); } } }); } }); Ext.application({ name: 'App', autoCreateViewport: false, launch: function() { Ext.create('App.view.prospects.Filter', { renderTo: Ext.getBody() }); var controller = Ext.create('App.controller.ProspectsFilter', { application: this }); controller.init(this); } }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt;&lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload