简体   繁体   English

剑道菜单选择问题

[英]Kendo Menu selection issue

I've a kendo menu to dynamically enable or disable the kendo grid columns. 我有一个Kendo菜单,可以动态启用或禁用Kendo网格列。 When I select the options from the KendoMenu, the selection is firing twice. 当我从KendoMenu中选择选项时,选择会触发两次。 I've created the demo version below. 我已经在下面创建了演示版本。

demo 演示

$("#menu").kendoMenu({
dataSource: [{
    text: "Menu",
    items: ds
}],
openOnClick: true,
closeOnClick: false,
open: function () {
    var selector;
    $.each(grid.columns, function () {
        if (this.hidden) {
            selector = "input[data-field='" + this.field + "']";
            $(selector).prop("checked", false);
        }
    });
},
select: function (e) {
    // don't show/hide for menu button --- calling twice
    if ($(e.item).parent().filter("div").length) return;

    console.log("******");

    var input = $(e.item).find("input.check");
    var field = $(input).data("field");
    if ($(input).is(":checked")) {
        grid.showColumn(field);
    } else {
        grid.hideColumn(field);
    }
}});

Check the console log while selecting the menu items. 选择菜单项时,请检查控制台日志。

Adding the checkbox to the menu item seems to lead to kendo firing the event for the menu click and the checkbox check. 将复选框添加到菜单项似乎会导致kendo触发菜单单击和复选框复选框的事件。 It seems hard to differentiate between the two instances, so it might be better to do something different to indicate the check. 似乎很难区分这两个实例,因此最好做一些不同的事情来指示检查。 The following icons can be used - maybe use the tick icon instead of an actual checkbox: 可以使用以下图标-可能使用对勾图标代替实际的复选框:

http://demos.telerik.com/kendo-ui/styling/icons http://demos.telerik.com/kendo-ui/styling/icons

I've fixed the issue with the updated code 我已经用更新的代码解决了这个问题

$("#menu").kendoMenu({
dataSource: [{
    text: "Menu",
    items: ds
}],
openOnClick: true,
closeOnClick: false,
open: function () {
    var selector;
    $.each(grid.columns, function () {
        if (this.hidden) {
            selector = "input[data-field='" + this.field + "']";
            $(selector).prop("checked", false);
        }
    });
},
select: function (e) {
    // don't show/hide for menu button
    if ($(e.item).parent().filter("div").length) return;
    var removeItemFlag = false;
    var input = $(e.item).find("label");
    var selectedValue = input[0].innerHTML;

    if(selectedValue)
    {
        for(var i=0; i< droplist.length; i++){
            if(droplist[i] === selectedValue){
                removeItemFlag = true
                input[0].classList.remove = "fa fa-check-square-o";
                input[0].className = "fa fa-square-o";
                break;
            }
        }
        var selectedIndex = droplist.indexOf(selectedValue);
        if (selectedIndex > -1 && removeItemFlag) {
            droplist.splice(selectedIndex, 1);
             grid.hideColumn(selectedValue);

        }else{
            droplist.push(selectedValue);
            grid.showColumn(selectedValue);
            input[0].className = "fa fa-check-square-o";
        }
    }
}

}); });

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

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