0

I am new to knockout.js. I have a Y/N value from my model that I want to bind to a checkbox.

This is my view:

<tbody id="tblMultiEdit" data-bind="foreach: UUTs">
<tr>
<td data-bind="text: SerialNumber"></td>
<td><input type="checkbox" data-bind="ReqDowngrade" /></td>
<td><input type="checkbox" data-bind="ACTSupported"/></td>
<td><input type="checkbox" data-bind="ProdModeOff"/></td>
</tr>
</tbody>

Knockout code:

function ViewModel(UUTs) 
{

var self = this;

self.UUTs = UUTs;

};

var viewModel = new ViewModel(@Html.HtmlConvertToJson(Model));

ko.applyBindings(viewModel);

So far I can bind the text with no problem, but checkboxes are in blank.

4
  • this one is incorrect data-bind="ReqDowngrade" Find how to bind inputs values here: knockoutjs.com/documentation/checked-binding.html Commented Jul 2, 2018 at 14:30
  • Thanks, now I need a way to convert Y/N to 0/1 within knockout for each row Commented Jul 2, 2018 at 15:25
  • can u update question with code u have now? Commented Jul 2, 2018 at 15:46
  • I resolved it. See answer. Thanks! Commented Jul 2, 2018 at 15:48

1 Answer 1

1

I was able to resolve this by adding a ternary operation.

<td><input type="checkbox" data-bind="checked: (ReqDowngrade == 'Y' ? 1 : 0)" /></td>

If anybody knows a more efficient way using knockout let me know!

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.