Javascript 如何将id绑定到启动菜单命令
我有一张有物品清单的桌子。我想使用Priming Menu作为下拉菜单选项,导航到具有所选项目id的其他页面。我想做的是,当我单击菜单项时,我想绑定所选项目的id 我的HTML看起来像这样Javascript 如何将id绑定到启动菜单命令,javascript,angular,typescript,primeng,Javascript,Angular,Typescript,Primeng,我有一张有物品清单的桌子。我想使用Priming Menu作为下拉菜单选项,导航到具有所选项目id的其他页面。我想做的是,当我单击菜单项时,我想绑定所选项目的id 我的HTML看起来像这样 <tr *ngFor="let item of items" class="animated fadeIn"> <td>{{item.category}}</td> <td>{{item.name}}</td> <td&
<tr *ngFor="let item of items" class="animated fadeIn">
<td>{{item.category}}</td>
<td>{{item.name}}</td>
<td>{{item.date}}</td>
<td>
<div>
<p-menu #tableMenu [popup]="true" [model]="tableMenuItems" appendTo="body"></p-menu>
<button type="button" pButton icon="pi pi-ellipsis-v"
class="ui-button-secondary ui-button-rounded ui-button-transparent"
(click)="tableMenu.toggle($event)">
</button>
</div>
</td>
</tr>
您可以创建一个属性来保存当前项,并在调用切换方法之前的单击事件中设置所选项 组成部分
selectedItem:any=null;
...
恩戈尼尼特(){
this.tableMenuItems=[
{
标签:“查看项目”,命令:(事件)=>{
console.log(this.selectedItem);
//this.viewItemDetail()//我想在这里绑定所选项目的item.id并导航到项目详细信息页面
}
},
{
标签:“编辑项目”,命令:(事件)=>{
this.editItem()//我想在这里绑定所选项目的item.id并导航到项目编辑页面
}
},
];
}
模板
{{item.category}
{{item.name}
{{item.date}
this.tableMenuItems = [
{
label: 'View Item', command: (event) => {
// this.viewItemDetail() // here I wanted to bind item.id of the selected item and navigate to item detail page
}
},
{
label: 'Edit Item', command: (event) => {
this.editItem() // here I wanted to bind item.id of the selected item and navigate to item edit page
}
},
];