私はSVGグラフィックでRodneyRehmのjQuerycontextMenuを使用しています。基本的な使用法では問題なく動作します。
ただし、コンテキストメニューをトリガーしたSVG要素のID(またはその他のプロパティ)を取得して、コンテキストメニューのアイテムリストで使用し、動的なアイテム名を取得する必要があります。
Simple Context Menuデモを使用していますが、クリックしたSVG要素のIDに応じて、これらの静的メニュー項目を動的メニュー項目に置き換えたいと考えています。
私はSVGグラフィックでRodneyRehmのjQuerycontextMenuを使用しています。基本的な使用法では問題なく動作します。
ただし、コンテキストメニューをトリガーしたSVG要素のID(またはその他のプロパティ)を取得して、コンテキストメニューのアイテムリストで使用し、動的なアイテム名を取得する必要があります。
Simple Context Menuデモを使用していますが、クリックしたSVG要素のIDに応じて、これらの静的メニュー項目を動的メニュー項目に置き換えたいと考えています。
これはあなたを助けるかもしれません:http://medialize.github.com/jQuery-contextMenu/demo/dynamic-create.html
ここにいくつかのサンプルコードがあります:
$(function(){
$.contextMenu({
selector: 'my-selector-here',
build: function($trigger, e) {
// this callback is executed every time the menu is to be shown
// its results are destroyed every time the menu is hidden
// e is the original contextmenu event, containing e.pageX and e.pageY (amongst other data)
// $trigger is the element that was rightclicked on - get its id here
var id = $trigger.getTheIDSomehow()
// build the menu items
if (id == 1) {
menuItems = {...}
else if (id == 2)
menuItems = {...}
return {
callback: function(key, options) {
// this is called when one of the contextmenu options is clicked
},
items: menuItems
};
}
});
});
静的メニューを使用すると、次のようなIDが取得されます。
...
callback: function (key, options) {
id = options.$trigger.attr("id");
...
},
...
たぶん$trigger.attr( "id")があなたのために働くかもしれません。
どの要素で右クリックが行われるかを確認する必要があります::
$.contextMenu({
selector: 'tr',
callback: function (key, options) {
var m = "clicked: " + key;
if (key == "Clone")
{
Your_Function($(this).attr('id'));
}
},
items: {
"Clone": { name: "Clone" },
}
});