简体   繁体   中英

How to add onclick event on checkbox in ember (hbs)

I have been added to project with ember. Unfortunetly I only know AngularJS. Anyway what I have to do is to add onclick event on checkbox. I've tried to use observer but without much success (probably because input is generated via iteration). Heres the code

{{#each prod in allProducts}}
            <tr>
                <td class="checkbox-event" selenium-id="check">{{input type=checkbox checked=prod.selected id=prod.id}}</td>
                <td selenium-id="id">{{prod.productNumber}}</td>
                <td selenium-id="name">{{prod.name}}</td>
                <td selenium-id="category">{{prod.mainCategoryName}}</td>
                <td selenium-id="price">{{prod.mainPrice}}</td>
            </tr>
{{/each}}

What I need to do is to add click event on input that will call some function with prod as argument. I have only found answers for 'normal' input but not the one above.

You have several problems:

  1. each prod in allProducts is wrong. Use {{#each allProducts as |prod|}}
  2. type=checkbox is wrong. Use type="checkbox"
  3. you can use change action.

    Checkout this twiddle link

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