PrimeNg上下文菜单传递数据问题 [英] PrimeNg context menu passing data issue
本文介绍了PrimeNg上下文菜单传递数据问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用PrimeNg的上下文菜单v6.0.1,问题是文档不清晰,我也无法在网上找到它以及如何将数据传递给命令功能,例如:
I am using PrimeNg's context menu v6.0.1, the problem is the documentation is not clear and I cannot find it over the web as well on how to pass data to command function e.g.:
我在屏幕上渲染了10个对象,并且上下文菜单附加到所有这些对象上,现在,如果我单击菜单项,我想获取在其上渲染了上下文菜单的目标对象的ID完成了吗?
I have 10 objects rendered on screen and context menu is attached to all of these objects, now if I click on menu item I want to get the id of the target object on which the context menu is rendered, how can this be accomplished?
<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>
这篇关于PrimeNg上下文菜单传递数据问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文