Java 启动选项卡菜单单击要为已禁用选项卡禁用的事件

Java 启动选项卡菜单单击要为已禁用选项卡禁用的事件,java,angular,typescript,primeng,tabmenu,Java,Angular,Typescript,Primeng,Tabmenu,对于已禁用的菜单,我在启动p-tabMenu时遇到问题 this.items = [ { label: "Home", icon: "pi pi-fw pi-home", command: event => { this.activateMenu(event); } }, { label: "Edit", icon: "pi pi-fw pi-pen

对于已禁用的菜单,我在启动
p-tabMenu
时遇到问题

this.items = [
  {
    label: "Home",
    icon: "pi pi-fw pi-home",
    command: event => {
      this.activateMenu(event);
    }
  },
  {
    label: "Edit",
    icon: "pi pi-fw pi-pencil",
    disabled: true,
    command: event => {
      this.activateMenu(event); // this one won't be triggered because tab is disabled
    }
  }
]

activateMenu(event) {
    console.log("click on " + event.item.label + " tab!");
}
比如说,我有一个带有4个子选项卡的选项卡菜单->AAA、BBB、CCC、DDD

这是在ts组件中设置菜单项的方式

//....

invDocs: InventoryDocs[] = [];
invMenu: InventoryDocs[] = [];
this.invMenu = this.data.cdMenu;
this.invDoc = this.data.cdDocs;
this.menuItems = []; 
if(this.invMenu != null && this.invMenu.length > 1){
    this.showMenu = true;
    for (let i = 0; i < this.invMenu.length; i++) {                  
        this.menuItems.push({label: this.invMenu[i].fileDescr, id:  this.invMenu[i].menuId, disabled: this.invMenu[i].subCount > 0});
        this.activeItem = this.menuItems[0];
    }
    this.currentPdf = this.invDoc.docBlob;
}
                
            


activateMenu(tab){ 
    console.log(tab);
    this.invDocId = tab.activeItem.id;
    this.showMenu = true;
    this.retriveCurrentPdf(this.invDocId);
}           
                
.....//
默认情况下,“AAA”设置为活动

我的组件html如下所示:

<div style="width: 3em;">
       <p-tabMenu #tab [model]="menuItems" [activeItem]="activeItem" (click)="activateMenu(tab)" class="customWrapper" ></p-tabMenu> 
</div> 

页面由4个选项卡呈现,其中AAA和DDD处于启用状态,BBB和CCC处于禁用状态。选项卡上的单击事件调用
activateMenu
方法,并在UI中显示差异pdf


问题在于此单击事件也会为禁用的按钮触发。尽管选项卡BBB、CCC已禁用,但它允许我单击该选项卡,但选项卡#中的activeItem保留了以前活动的内容,因此我无法停止事件传播。当页面加载时,默认为AAA选项卡。现在,即使BBB是禁用的,它也允许我单击选项卡“BBB”,当我打印
控制台时。在
activateMenu()中记录
标签和id中的活动项显示选项卡AAA的活动项。有人能建议我如何防止单击禁用的选项卡吗?

我认为您应该使用
命令
功能,它是
菜单项
的一部分。只有在选项卡未禁用的情况下,此功能才会在单击时触发

this.items = [
  {
    label: "Home",
    icon: "pi pi-fw pi-home",
    command: event => {
      this.activateMenu(event);
    }
  },
  {
    label: "Edit",
    icon: "pi pi-fw pi-pencil",
    disabled: true,
    command: event => {
      this.activateMenu(event); // this one won't be triggered because tab is disabled
    }
  }
]

activateMenu(event) {
    console.log("click on " + event.item.label + " tab!");
}