Hi,

I'm making good use of the excellent contextMenu plugin.
However, I have a little problem with the callback when
the menu has been triggered. I want to get hold of which
menu element that was choosen. Since I setup the menu
programmatically, I can't hardcode the value. Perhaps,
my poor Javscript knowledge is failing me...

I setup an object for the contextMenu binding option like this:

this.cm_owners = new Object();


for (var i=0; i < owners.length; i++) {


  this.cm_owners["#"+owners[i]] = function(t)
{this.saveOwner(owners[i],t.id);}.bind(this)

}

then, later on I setup the menu:

  $("td.owner").contextMenu("#ownerMenu", {


      bindings : this.cm_owners


  });

but this dosn't work, owners[i] is not bound in the closure...(why ?)

Well, I ended up modifying jquery.contextmenu.js so that it
also send in the menu Id, thus the above becomes:

this.cm_owners = new Object();


for (var i=0; i < owners.length; i++) {


  this.cm_owners["#"+owners[i]] = function(t,k)
{this.saveOwner(k,t.id);}.bind(this)

}

Below is the diff for the contextMenu plugin code.

Surely I'm doing something wrong so any hints...

Cheers, Tobbe


--- jquery.contextmenu.js       2007-03-30 00:18:00.000000000 +0200
+++ jquery.contextmenu.js~      2007-03-09 00:05:50.000000000 +0100
@@ -83,7 +83,7 @@
     $.each(cur.bindings, function(id, func) {
       $(id, menu).bind("click", function() {
         hide();
-        func(trigger, id);
+        func(trigger);
       });
     });
     menu.css({"left":e.pageX,"top":e.pageY}).show();


_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to