简体   繁体   English

jQuery contextMenu标题和子菜单上的功能

[英]Jquery contextMenu title and function on submenu

I'm creting a jquery context menu, using https://swisnl.github.io/jQuery-contextMenu/ . 我正在使用https://swisnl.github.io/jQuery-contextMenu/创建一个jQuery上下文菜单。

I've sucessfully done the creation part of the submenu. 我已经成功完成了子菜单的创建部分。 I had to use build, in order to have some data that is only available on runtime. 我必须使用build,以便拥有一些仅在运行时可用的数据。 This data appears on a submenu, and I need to have a title on each of those submenu items, as well as click funtion on each of them. 此数据出现在子菜单上,我需要在每个子菜单项上都有标题,并在每个子菜单项上单击功能。

I cant seem to make it work, both the title and the function on those submenu items. 我似乎无法使这些子菜单项的标题和功能都起作用。

Here is my code: 这是我的代码:

$.contextMenu({
        selector: '.gridRelatorioCursorMorada',
        build: function ($triggerElement, e) {
            var coords = $triggerElement[0].attributes['data-coord'].nodeValue;
            var coordsArray = coords.split(',');
            return {
                callback: function (key) {
                    if (key === 'get') {
                        getdata();
                    }
                },
                items: {
                    get: {
                        name: "Get data"
                    },
                    see: {
                        name: "See data",
                        items: {
                            normal: { name: coords },
                            graus: { name: dd2dms(coordsArray[0], coordsArray[1]) },
                            siresp: { name: decimalToSIRESPCoordinates(coordsArray[0], coordsArray[1]) }
                        }

                    }
                }
            };
        }
    });

Since the events part of contextMenu doesnt work with build, I dont know what else to do. 由于contextMenu的事件部分不适用于构建,因此我不知道该怎么办。 I've also added the following code: 我还添加了以下代码:

$(document).on('contextmenu',  function () {
        $('.context-menu-submenu > ul > li').attr('title', 'tituro');
});

But it also doesnt work. 但是它也不起作用。

My mistake. 我的错。

Event does work on build. 事件确实适用于构建。 This got me to get the title on each of the submenu items. 这使我获得了每个子菜单项的标题。

The click function I got it working with the callback function. 点击功能我得到它与回调功能一起使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM