Question

can anyone tell me why all checkboxes get selected when one is checked?

I´d like to get the ids of the selected checkboxes.

http://emberjs.jsbin.com/poqabavi/2/edit

thank you

Was it helpful?

Solution

I believe it is because once you click on a checkbox for the first time, isChecked becomes true, which updates every checkbox that relies on that variable.

One way to get around this is to set the isChecked attribute on the Company model:

App.Company = DS.Model.extend({
  name: DS.attr('string'),
  people: DS.hasMany('person', {async: true}),
  isChecked: false
});

And your checkbox code would be {{input type="checkbox" checked=company.isChecked}}.

Then you can easily get which ones are checked by iterating over the content.

Here is the updated JSbin with my suggestions:

OTHER TIPS

In the current state of your application, all the checkboxes are referring to the same variable, IndexController.get('isChecked') and IndexController.set('isChecked', value). If you change that variable's scope from the controller to the individual Company models, it will work as desired.

<td> {{input type="checkbox" checked=company.isChecked}}</td>

Once that's changed, you can use var companies = this.content.filterBy('isChecked') in your IndexController to get the companies that have been checked in the form.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top