我正在使用 PrimeNg 的上下文菜单 v6.0.1,问题是文档不清楚,我也无法在网络上找到有关如何将数据传递给命令函数的信息,例如:
我在屏幕上渲染了 10 个对象,并且上下文菜单附加到所有这些对象,现在如果我单击菜单项,我想获取渲染上下文菜单的目标对象的 id,这怎么可能完成了吗?
<div id="block-container" *ngFor="let block of blocks">
<!-- where to attach this block object ??? -->
<p-contextMenu appendTo="body"
[target]="blockContextMenu"
[model]="contextMenuItems">
</p-contextMenu>
<div #blockContextMenu>
Some implementation...
</div>
</div>
以下是我的元素模型:
this.contextMenuItems = [
{
label: 'Trip Details',
command: (event) => {
// event doesn't contain anything useful,
// and only has the clicked menu item specific information.
}}
];
最佳答案
@ViewChild('copyMenu') copyMenu: ContextMenu;
onLinkRightClicked(content: string, e: any): void {
if (this.copyMenu) {
let model: MenuItem[] = [];
model.push({ label: 'Action', command: (event) => this.doAction(content) });
this.copyMenu.model = model;
this.copyMenu.show(e);
}
}
doAction(content){
// here
}
<div #blockContextMenu (contextmenu)="onLinkRightClicked(content, $event)">
Some implementation...
</div>
<p-contextMenu appendTo="body" #targetContextMenu>
</p-contextMenu>
关于angular - PrimeNg 上下文菜单传递数据问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51480381/