弹出右键菜单时,根据当前选择的行,显示隐藏、启用禁用菜单项。

示例地址:demo/DiyMenu.html

代码如下:

//右键菜单弹出
var menu = new ProjectMenu();
project.setContextMenu(menu);
menu.edit.on("click", function (e) {
    ShowTaskWindow(project);
});

//监听菜单的opening事件,此事件在菜单显示前激发。可以控制菜单项的显示和可操作。menu.on("opening", function (e) {
    var project = this.owner;       //PlusProject对象
    var task = project.getSelected();
    if (!task) {
        e.cancel = true;
        return;
    }
    //显示和可编辑所有菜单项
    this.add.show();
    this.edit.show();
    this.remove.show();
    this.upgrade.enable();
    this.downgrade.enable();
    if (task.Summary) {
        this.edit.hide();
        this.remove.hide();

        this.upgrade.disable();
        this.downgrade.disable();
    } else {
        this.add.hide();
    }
});