0

I have an observable array of observable objects called FieldsAndValues enter image description here

I'm binding the values of each object by their index using this

<input type="radio" data-bind="checked: DTO.FieldsAndValues()[0].Value, checkedValue: 'true'" class="separate" name="rdo">Yes

<input type="radio" data-bind="checked: DTO.FieldsAndValues()[0].Value, checkedValue: 'false'" class="separate" name="rdo">No

My question is, is there a way to bind the objects using the LeaveFieldName property as a selector and not their index?

1 Answer 1

1

Isn't it just the case of using foreach binding on that array, and not manually specifying the index of each node?

e.g.

<div data-bind="foreach: DTO.FieldsAndValues">
    <div>
        <input type="radio" data-bind="checked: LeaveField.LeaveFieldName, checkedValue: true" class="separate" name="rdo">Yes
        <input type="radio" data-bind="checked: LeaveField.LeaveFieldName, checkedValue: false" class="separate" name="rdo">No
    </div>
</div>

Plus, even if you bind it, your value will be either true / false, not the IsRegularAndProbiSeparate (etc.). That's what checkedValue binding is for. You even stringify boolean which isn't a good idea, should be just checkedValue: true

Alternatively you could use with binding (with: LeaveField) inside the array output and have access to all properties in each recurrence.

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.