简体   繁体   中英

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,

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

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}}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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