我正在使用Ember版本2.5.1餘燼複選框 - 選擇1,並非全部全選
我已設置複選框,並且它們在選中時工作。但是,當我選擇一個框時,對於一個用戶,所有用戶都會選中所有框。例如,如果我爲Sophie選擇一個團隊(Speedy),那麼每個複選框最終都會被檢查並加入Speedy團隊。我如何解決這個問題?做到這一點,每個人都可以在不同的團隊中。
例如outwork是每個人的名字列表,(如果'Team Speedy'被勾選),每個人名字旁邊是'Team Speedy'。
teams.hbs;
<div class="container">
<table class="table">
<thead class="thead-inverse">
<tr>
<th>Name</th>
<th>Team Speedy</th>
<th>Team Alpha</th>
<th>Team Invincible</th>
</tr>
</thead>
<tbody>
{{#each model as |signed-player|}}
<tr>
<td> {{signed-player.name}} </td>
<td> {{input type='checkbox' checked=speedy}} </td>
<td> {{input type='checkbox' checked=alpha}} </td>
<td> {{input type='checkbox' checked=invincible}} </td>
</tr>
{{/each}}
</tbody>
</table>
{{#each model as |signed-player|}}
<p><b>{{signed-player.name}}</b> is on the following team: <b>{{teamName}}</b></p>
{{/each}}
</div>
控制器/ team.js
speedy: false,
alpha: false,
invincible: false,
teamName: function()
{
if (this.get('speedy')) {
return 'Team Speedy';
}
else if (this.get('alpha')) {
return 'Team Alpha';
}
else if (this.get('invincible')) {
return 'Team Invincible';
}
else {
return 'No team yet';
};
}.property('speedy', 'alpha', 'invincible'),
我認爲你的問題是,控制器是單身人士。這意味着即使用戶更改,當您修改路線時,複選框仍會保持選中狀態。因此,在setupController(控制器,模型)中的路由中嘗試使用controller.set('speedy',null)重置它們 –