PrimeNG、SplitButton:如何将参数输入模型? [英] PrimeNG, SplitButton: How to get a parameter into the model?

查看:43
本文介绍了PrimeNG、SplitButton:如何将参数输入模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我想通过 PrimeNG SplitButton 触发函数 foo 和 bar.两者都有一个关于按钮本身的参数.

Lets say I want to trigger functions foo and bar by a PrimeNG SplitButton. Both have one parameter regarding the button itself.

关于操作,我想为分配的功能设置参数.

Regarding the action I want to have parameter for the assigned function.

我可以为 foo 做,因为我是用 onClick 设置的.

I can do it for foo because I set it with onClick.

但是对于酒吧我该怎么做呢??

But how can I do it for bar??

    <p *ngFor="let x of ['aaa','bbb','ccc']">
      <p-splitButton label="FOO for {{x}}" (onClick)="foo (x)" [model]="cmds"></p-splitButton>
    </p>

    cmds : any = [{label: "BAR for x", command: () => { bar (x); }}];   // x is not here, how can I get it?

推荐答案

发现我也可以在那里绑定一个函数.

Found out I can bind a function there too.

    <p *ngFor="let x of ['aaa','bbb','ccc']">
      <p-splitButton label="FOO for {{x}}" (onClick)="foo (x)" [model]="cmds (x)"></p-splitButton>
    </p>

    cmds (x) : any
    {
      return [{label: "BAR for "+x, command: () => { bar (x); }}];   
    }

这篇关于PrimeNG、SplitButton:如何将参数输入模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆