1

我在嵌套网格的 JqWidgets 上下文菜单中面临双重发布问题。该事件正在触发 n 次(其中“n”是我单击上下文菜单的时间)

除此之外,如果我将事件处理程序方法保留在上下文菜单创建之外,而不是在这种情况下事件处理程序没有被调用

场景 1(我遇到双重发布问题,无法获取选定的行列值)

//handle context menu clicks.
var teamButtonClick = function (event) {

    try{

           // create context menu for Task
           var taskContextMenu = jQuery("#teamMenu").jqxMenu({ width: 160, height: 162, autoOpenPopup: false, mode: 'popup'});
           jQuery("#<portlet:namespace />teamGrid").on('contextmenu', function () {
               return false;
           });
           jQuery("#teamMenu").on('itemclick', function (event) {
               try {
                   var args = event.args;
                   var rowindex = jQuery("#teamGrid").jqxGrid('getselectedrowindex');
                   if (jQuery.trim(jQuery(args).text().trim()) == "Add User") {
                        editrow = rowindex;
                        jQuery("#rowId").val(editrow);
                        var dataRecord = jQuery("#teamGrid").jqxGrid('getrowdata', args.rowindex);  
                        alert(dataRecord);                  
                    }
               }catch(e) {alert(e);}
           });

           var buttonID = event.target.id;      
           jQuery("#teamGrid").jqxGrid('selectrow', buttonID);
           var scrollTop = jQuery(window).scrollTop();
           var scrollLeft = jQuery(window).scrollLeft();
           taskContextMenu.jqxMenu('open', parseInt(event.clientX) + 5 + scrollLeft, parseInt(event.clientY) + 5 + scrollTop);
           return false;
         }catch(e) {
            alert('error in contextmenu: ' + e);
         }
}

场景 2(当我保持在上下文菜单创建块之外时,我的事件处理程序没有被调用)

// event handler is not getting called in this case
jQuery("#teamMenu").on('itemclick', function (event) {
   try {
       var args = event.args;
       var rowindex = jQuery("#teamGrid").jqxGrid('getselectedrowindex');
       if (jQuery.trim(jQuery(args).text().trim()) == "Add User") {
            editrow = rowindex;
            jQuery("#rowId").val(editrow);
            var dataRecord = jQuery("#teamGrid").jqxGrid('getrowdata', args.rowindex);  
            alert(dataRecord);                  
        }
   }catch(e) {alert(e);}
});

//handle context menu clicks.
var teamButtonClick = function (event) {

    try{

           // create context menu for Task
           var taskContextMenu = jQuery("#teamMenu").jqxMenu({ width: 160, height: 162, autoOpenPopup: false, mode: 'popup'});
           jQuery("#<portlet:namespace />teamGrid").on('contextmenu', function () {
               return false;
           });

           var buttonID = event.target.id;      
           jQuery("#teamGrid").jqxGrid('selectrow', buttonID);
           var scrollTop = jQuery(window).scrollTop();
           var scrollLeft = jQuery(window).scrollLeft();
           taskContextMenu.jqxMenu('open', parseInt(event.clientX) + 5 + scrollLeft, parseInt(event.clientY) + 5 + scrollTop);
           return false;
         }catch(e) {
            alert('error in contextmenu: ' + e);
         }
}

提前致谢

4

1 回答 1

0

事件可以引发 n 次,前提是您绑定到它 n 次。检查您的代码多少次调用绑定到“itemclick”的 teamButtonClick 函数。如果“itemclick”被调用超过 1 次,则超过 1 次 :)

于 2015-04-17T10:58:36.657 回答