I tried it is as described in the API, but it didn't work...
what's wrong?
error msg: options has no properties..
function showMenu( e, tabPanel, tab)
{
var menu = new Ext.menu.Menu({ id: 'mainMenu' });
var sameLevelItem = menu.add({
text: 'Add Tab On Same Level', //LNG
id: 'sameLevel'
});
sameLevelItem.on('click', addNewTabClicked, this, {
someOption: 'test'
});
menu.show( e.getTarget() );
}
function addNewTabClicked( e, item, options)
{
alert(options.someOption);
}
Options that are passed when installing an event handler are handler configuration properties. They are not custom options. You need to use createDelegate method to pass custom options to an event handler.
That's not entirely accurate. As the docs show, you can pass custom args. This works when you add a handler to an Element, but does not work as in the OPs post when you try to add it to the menu item.
Ext.get('lnk').on('click', test, this, {single:true, foo:'bar'});
@animal: yeah, I mentioned it afterwards that it is originally from Observable.
@hendricd: I'm using now your approach with createDelegate.. thanks btw. you helped me alot. ;)
Docs are clear as mud on this one. ~o)
@ko0kiE - What did you end up using ?
That's the standard addListener method from Observable. You don't have to use those options.
hmmm.. anyone care to report this possible documentation lapse in the doc bugs thread?
Oh yes, now I see it in Element's doc. Element and Observable use different addListener methods, firing of the event is apparently different too.
I've tried to find some custom options in event handler of Observable subclass and they are really not there. (Well, they're buried somewhere deep in listeners but cannot be easily accessed and they are not passed as arguments to the handler.) Project 3: XML for All Occasions:: event handlers will be implemented as methods of a content handler object. . First, you can’t simply “pass through” tags (write them directly to the HTML http://www.springerlink.com/index/pn58p26778370th8.pdfHOME |
I would be useful if this worked also for Observable so please post it Feature Requests forum.
Which issue ?
A variation:
this.myMenu.on("hide", this.resetSomeHandlers.createDelegate(this,[myIcon],true), null, {single: true});
would pass append myIcon as the last parameter of the event handler.
Options that are passed when installing an event handler are handler configuration properties. They are not custom options. You need to use createDelegate method to pass custom options to an event handler. 5 Web browsers — HTML 5:: When a script's global object is an empty object, it can't do anything .. ( The listener argument is emphatically not the event handler attribute itself. http://www.whatwg.org/specs/web-apps/current-work/multipage/browsers.htmlHOME |
Ok, I'll post it in feature requests, it would be easier if addListener worked nearly the same for an Observable subclass custom event as it does for an Ext.Element. Of course it probably won't be exactly the same, since an Ext.Element event like a click for example corresponds to a browser event, whereas Observable events do not.
In the meantime I see it as a documentation bug -- the Observable addListener docs shouldn't use an Ext.Element event as the example really. Minor, but can lead to a bit of wasted time for developers.
Docs are clear as mud on this one. ~o)
I thought they were good. Can you suggest improvements to this:
http://extjs.com/deploy/ext/docs/output/Ext.util.Observable.html#addListener
?
I ran into the same problem and came across this thread, and here's my take:
The Observable addListener docs (in 2.0 and 1.1) seem to be just cut and pasted from the Ext.Element addListener docs. But the calling signatures seem to be quite different, so either the docs should be different or the API should be brought in line. Probably the former, since the Observable events are not based on an actual browser event like a click or the like.
For example, I had something like this in my code:
this.myMenu.on("hide", this.resetSomeHandlers, this, {single: true, icon: myIcon});
I wanted to pass 'myIcon' to the resetSomeHandlers method. Didn't work, although the example in Observable.addListener makes it look like it should. The resetSomeHandlers method gets called on menu hide alright, but with just a single arg -- the menu object itself, which isn't too useful.
So you have to work around it by creating a dynamic function each time. That's ok, but not the greatest. Plus searching the docs and then checking the forums to see if there is some other way to do it could be avoided if the docs mentioned the differences between an Ext.Element event call and an Observable event call, or at least didn't have a misleading example.
Unless anyone disagrees with my assessment I'll post something to the docs thread in a bit.
trust me to miss the specifics :">
That options block you are using is really for single-use-type events
please file a report if the docs fail to mention this. thanks.
i can't seem to find this API @ko0kiE was referring to...
I'm not sure whether that's a doc bug or whether the Observable implementation is truly different that the Element implementation.
I agree that the createDelegate way works.
I'm moving this to the Premium forum, so that Jack/Brian can take a look/comment.
That options block you are using is really for single-use-type events. Where your menu event is to be used many times, you are better off considering something like:
sameLevelItem.on('click', addNewTabClicked.createDelegate(sameLevelItem,['somevalue1',1400],true));
Then your callback would receive the parameter signature as:
var addNewTabClicked = function ( e, item, value1, value2)
{
console.log(arguments); // check them out...
alert(value1);
}
i can't seem to find this API @ko0kiE was referring to...
there:
http://extjs.com/deploy/ext-1.1/docs/output/Ext.menu.Item.html#addListener
a click on a menu item isn't really a single-event-type, is it? :-/
I Am a Sinner – What About You?
Global Sourcing and Supplier Online by Dylan
|