Hybrid View
-
15 Aug 2008 11:04 PM #1
[2.2] Cannot use custom arguments in listener handler
[2.2] Cannot use custom arguments in listener handler
In the API documentation, addListener method accepts four arguments
The fourth argument can contain custom options (like forumID in the above example).PHP Code:el.on('click', this.onClick, this, {
single: true,
delay: 100,
forumId: 4
});
But, when the handler function is called, the customs options are not passed.
Example:
Firebug returns undefined for optionsPHP Code:Ext.onReady(function(){
var myButton = new Ext.Button({
text: 'Click Me'
});
var onClick = function (observable, e, options) {
console.log(options);
};
myButton.on('click', onClick, myButton, {myArgument:'Custom'});
myButton.render(document.body);
});
This bugs comes from the Ext.util.Observable.prototype.fire method (Observable.js)
It should bePHP Code:fire : function(){
var ls = this.listeners, scope, len = ls.length;
if(len > 0){
this.firing = true;
var args = Array.prototype.slice.call(arguments, 0);
for(var i = 0; i < len; i++){
var l = ls[i];
if(l.fireFn.apply(l.scope||this.obj||window, arguments) === false){
this.firing = false;
return false;
}
}
this.firing = false;
}
return true;
}
PHP Code:fire : function(){
var ls = this.listeners, scope, len = ls.length;
if(len > 0){
this.firing = true;
var args = Array.prototype.slice.call(arguments, 0);
for(var i = 0; i < len; i++){
var l = ls[i];
args.push(l.options); // options are appended to args array
if(l.fireFn.apply(l.scope||this.obj||window, args) === false){ // args instead of arguments
this.firing = false;
return false;
}
}
this.firing = false;
}
return true;
}
-
16 Aug 2008 12:44 AM #2Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 41
There was a discussion on how to implement custom arguments for addListener. I think that in the end the option was removed, but the API docs weren't updated.
You can accomplish the same with:
Code:el.on('click', this.onClick.createDelegate(this, [4], true), this, { single: true, delay: 100 });
-
17 Aug 2008 2:48 PM #3
I just added a custom argument to a 'click' event handler today and it worked fine O_o.
-
13 Oct 2009 2:42 AM #4
Problem when firing an event
Problem when firing an event
Hello,
I have this problem when firing a custom event, at the next line:
this.fireEvent("myEvent", anObjectAsParameter);
I receive the next error:
l.fireFn has no properties
(?)()(Object scope=Object options=Object)ext-all-debug.js (line 2124)
apply()(Object 0=Object, function(), undefined)ext-base.js (line 7)
fire()()ext-all-debug.js (line 2122)
fireEvent()()
...............
* if (l.fireFn.apply(l.scope || me.obj || window, args) === FALSE) {
Any ideea?
-
13 Oct 2009 5:33 AM #5Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 41
You added listener that isn't a function.
ps. Next time, please start a new thread if you have a different problem.


Reply With Quote