I know this topic has been addressed a few times but I'm having a bit of trouble here. I have the following in my view:
<!-- ko foreach: documents -->
<div>
<input type="checkbox" data-bind="checked: $parent.checkItem(documentId)" />
</div>
<!-- /ko -->
In my viewModel:
var checkItem = function (checkedItem) {
debugger;
window.selectedDocuments.push(checkedItem);
};
I'm using window because another resource needs access to this array.
Right now, when I load the page the checkItem is hit one time for each document, which I don't think it should. I'm trying to monitor which documents have been selected, keeping an array updated (in this case, selectedDocuments).
Here's a fiddle with my attempt:
How can I make this work?