1
Patient 1
    Patient.Age = '25'
    Patient.Injury[0].Date = '2015-01-01'
    Patient.Injury[0].Type = 'Burned'
    Patient.Injury[1].Date = '2015-01-27'
    Patient.Injury[1].Type = 'Sprained Ankle'

Patient 2
    Patient.Age = '17'
    Patient.Injury[0].Date = '2015-01-08'
    Patient.Injury[0].Type = 'Papercut'

<!-- ko foreach: Patient -->
<input type="checkbox" data-bind="checked: ?"> Sprained Ankle
<input type="checkbox" data-bind="checked: ?"> Burned
<input type="checkbox" data-bind="checked: ?"> Papercut
<!-- /ko -->

Looping through an array of multiple patients and displaying a list of checkboxes of injury types of each patient. How do I select multiple checkboxes per patient, based off of sub-array of injuries?

1 Answer 1

2

I suppose that you somewhere should have a list of all possible injuries let say that will be in a parent view model (along to collection of patients) and called AllInjuries also you will need to add some method to your Patient class what will iterate through all patient's injuries and will determine if that patient has that injury, let say it called hasInjury. Then you will be able to use something like this:

<!-- ko foreach: Patient -->
    <!-- ko foreach: $parents[1].AllInjuries -->
        <input type="checkbox" data-bind="checked: $parent.hasInjury($data.Type)">
        <span data-bind="text: Type"></span>
    <!-- /ko -->
<!-- /ko -->
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.