簡體   English   中英

如何在 Ember Js 中的 If 語句中調用操作

[英]How to call a action inside If statement 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>

不確定到底是什么不起作用,但我可以將其寫為:

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

首先,您需要創建一個助手。 哪個檢查您的兩個ID是否相等。

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

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

然后你的模板你需要做:

{{#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