简体   繁体   English

如何在 Ember Js 中的 If 语句中调用操作

[英]How to call a action inside If statement in Ember Js

Iam new to ember, Below is my ember js code for loop the entity array, in the if statement im cheking two ids are equal for render check box as disable, but this approach is not working, how can do this in ember js,我是 ember 新手,下面是我的 ember js 代码,用于循环实体数组,在 if 语句中,我将渲染复选框的两个 id 相等检查为禁用,但是这种方法不起作用,如何在 ember js 中执行此操作,

 {{#each this.model.data as |entity|}}
    
                <tr >

                {{#if entity.workflowTask.id == this.currentlyLoggedUserId }}

                  <td><input type="checkbox"  disabled="false"> </td>
                  {{else}}
                  <td><input type="checkbox"  checked={{this.allChecked}} onclick={{action 
                 (action "getSelectedMerchant" entity.id) value="target.checked" }} > </td>
                  {{/if}}
    </tr>

Not sure exactly what isn't working, but I might write this as:不确定到底是什么不起作用,但我可以将其写为:

{{#each this.model.data as |entity|}}
  <input
    type="checkbox"
    disabled={{(eq entity.workflowTask.id this.currentlyLoggedUserId)}}
    {{on "click" (fn this.getSelectedMerchant entity.id)}}
  />
{{/each}}

First, you need to create a helper.首先,您需要创建一个助手。 Which check your two ids are equal or not.哪个检查您的两个ID是否相等。

import { helper } from "@ember/component/helper";

export default helper(function isEqual(params /*, hash*/) {
const [val1, val2] = params;
return val1 === val2;
});

Then your template you need to do:然后你的模板你需要做:

{{#each this.model.data as |entity|}}
  <input
    type="checkbox"
    disabled={{(is-equal entity.workflowTask.id 
    this.currentlyLoggedUserId)}} />
{{/each}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM