0

以下是来自https://github.com/medialize/jQuery-contextMenu的示例。

我需要做的是在“选择器:”中放置一个函数,该函数将使用一堆逻辑来决定元素候选资格。

有什么建议么?

$(function(){
    $.contextMenu({
        selector: '.context-menu-one', 
        callback: function(key, options) {
            var m = "clicked: " + key;
            window.console && console.log(m) || alert(m); 
        },
        items: {
            "edit": {name: "Edit", icon: "edit"},
            "cut": {name: "Cut", icon: "cut"},
            "copy": {name: "Copy", icon: "copy"},
            "paste": {name: "Paste", icon: "paste"},
            "delete": {name: "Delete", icon: "delete"},
            "sep1": "---------",
            "quit": {name: "Quit", icon: "quit"}
        }
    });

    $('.context-menu-one').on('click', function(e){
        console.log('clicked', this);
    })
});
4

1 回答 1

1

try that:

setContextMenu: function () {
    $.contextMenu({
        selector: '.dataTable tbody tr',
        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)
            return {
                callback: function (key, options) {
                    var obj = eval("(" + $(this).attr("valor") + ")");

                    if (key == "Editar") {
                        console
                    }

                    if (key == "Visualizar") {

                    }
                },
                items: {
                    "sep1": "---------",
                    "Editar": { name: "Editar", style: "ui-icon-document" },
                    "sep2": "---------",
                    "Visualizar": { name: "Visualizar", style: "ui-icon-closethick" },
                    "sep3": "---------",
                }
            };
        }
    });
}
于 2014-09-02T22:42:12.127 回答