NNKL.COM
welcome to my space
X
Search:  
 HOME   can't pass custom arguments to event handler
can't pass custom arguments to event handler
Published by: wktd 2009-01-08
Welcome to:nnkl.com

  • 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.pdf
    HOME

    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.html
    HOME


  • 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

    You are looking at:nnkl.com's can't pass custom arguments to event handler, click nnkl.com to home
  • need help with nyc mileage run
  • unbelievable a 299 syd lgw one way on charter airline one day only
  • ord lhr sunday night stay 199 297 after taxes
  • short of 700 flight miles on ual
  • several cheap lon u s fares gbp113 lon sea sfo
  • transfering between lax lgb
  • mileage run or vacation how do you view it
  • sfo pwm on ua or us
  • nw 4 stop usa ex nrt wow
  • mr phx lgw on co for 367 leave dec 6 return dec 7
  • no dice on lh s 200 fares unexpected response
  • mr ord
  • not only lon is on sale 197 245
  • need help ua den sat or aus run
  •  
  • best coach to london
  • hnl fpo bahamas 261 on us dl
  • ord lhr 230
  • nw cmh run help
  • site 59
  • short less than 500 mile northwest mileage run needed help
  • dusit thani
  • multiple us cities to lon 205 on britsh airways
  • co matches ba sale
  • lax sfo nrt itm kix sfo lax den lax phx for usd 96 50
  • need 372 cheap delta miles to post by 11 16
  • need help for aa mr
  • mr on aa from mci
  •  Homepage | Add to favorites | Contact us | Exchange links | LOGIN | Site map | 
    Copyright© 2008 nnkl.com        Site made:CFZ