I'm working in Knockout and I'm trying to get specific information when a specific checkbox is checked. However, what's happening is every checkbox is being selected/deselected when I click on one. My question is, how do I prevent that from happening and make it to where only the check box I select/deselect is checked/unchecked?
JS I've simplified this to show just the code I'm working with.
export class Model{
isSelected: KnockoutObservable<boolean>;
constructor(){
this.isSelected = ko.observable(false);
}
selectStuff = () => {
return true;
}
}
HTML
<div data-bind="foreach: stuffToLoopThrough">
<input type="checkbox" class="checkbox" name="checkBox" data-bind="checked: $root.isSelected, click: $root.selectStuff" />Send Stuff
<input type="checkbox" class="checkbox" name="checkBox" data-bind="checked: $root.isSelected, click: $root.selectStuff" />Send Stuff
<input type="checkbox" class="checkbox" name="checkBox" data-bind="checked: $root.isSelected, click: $root.selectStuff" />Send Stuff
</div>
So what's happening here is, if I were to click on one of the three check boxes, every checkbox would be selected, I want just the check box I selected to be checked. How do I make that happen? Where am I going wrong here?
Aucun commentaire:
Enregistrer un commentaire