2

我正在尝试以与此问题类似的方式将Martin Wendt 的上下文菜单控件与FullCalendar一起使用。

每当右键单击事件时,都应该出现上下文菜单,但问题是我在 chrome 开发人员控制台中收到以下 javascript 错误。

jquery.min.js:3 Uncaught TypeError: ((r.event.special[g.origType] || {}).handle || g.handler).apply is not a function
    at HTMLDocument.dispatch (jquery.min.js:3)
    at HTMLDocument.q.handle (jquery.min.js:3)

我已经设置了一个示例jsfiddle来说明这个问题。下面列出了完整的 html 示例以供将来参考,以防链接失效。

<html>
<head>
    <meta charset='utf-8' />
    <link href="../Scripts/assets/plugins/calendar/dist/fullcalendar.min.css" rel="stylesheet" />
    <link rel="stylesheet" href="../Content/jquery.contextMenu.min.css">

    <style>
        body {
            margin: 40px 10px;
            padding: 0;
            font-family: Arial, Helvetica Neue, Helvetica, sans-serif;
            font-size: 14px;
        }

        #calendar {
            max-width: 900px;
            margin: 0 auto;
        }
    </style>
</head>
<body>

    <div id='calendar'></div>

    <script src='../Scripts/assets/plugins/jquery/jquery.min.js'></script>
    <script src="../Scripts/assets/plugins/calendar/jquery-ui.min.js"></script>
    <script src="../Scripts/assets/plugins/moment/moment.js"></script>

    <script src='../Scripts/assets/plugins/calendar/dist/fullcalendar.min.js'></script>

    <script src="../Scripts/jquery.contextMenu.min.js"></script>
    <script src="../Scripts/jquery.ui.position.js"></script>
    <script>

            $('#calendar').fullCalendar({
                defaultDate: '2019-08-12',
                editable: true,
                eventLimit: true,
                events: [
                    {
                        title: 'All Day Event',
                        start: '2019-08-01'
                    },
                    {
                        title: 'Long Event',
                        start: '2019-08-07',
                        end: '2019-08-10'
                    },
                    {
                        title: 'Conference',
                        start: '2019-08-11',
                        end: '2019-08-13'
                    },
                    {
                        title: 'Meeting',
                        start: '2019-08-12T10:30:00',
                        end: '2019-08-12T12:30:00'
                    }
                ]
                ,
                eventRender: function (event, element) {
                    var originalClass = element[0].className;
                    element[0].className = originalClass + ' hasmenu';
                },
                dayRender: function (day, cell) {
                    var originalClass = cell[0].className;
                    cell[0].className = originalClass + ' hasmenu';
                }
            })

            $(document).contextmenu({
                delegate: ".hasmenu",
                preventContextMenuForPopup: true,
                preventSelect: true,
                menu: [
                    { title: "Cut", cmd: "cut", uiIcon: "ui-icon-scissors" },
                    { title: "Copy", cmd: "copy", uiIcon: "ui-icon-copy" },
                    { title: "Paste", cmd: "paste", uiIcon: "ui-icon-clipboard", disabled: true },
                ],
                select: function (event, ui) {
                    // Logic for handing the selected option
                },
                beforeOpen: function (event, ui) {
                    ui.menu.zIndex($(event.target).zIndex() + 1);
                }
            });

    </script>

</body>
</html>
4

1 回答 1

1

看起来你包含了错误的库,至少如果你想使用jquery-ui-contextmenu

尝试

<link href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" rel="stylesheet" />
<script src="//code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="//code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<script src="assets/jquery.ui-contextmenu.min.js"></script>

代替

 <script src="../Scripts/jquery.contextMenu.min.js"></script>
于 2019-09-20T19:13:58.927 回答