<!-- ko if:name == 'Setup' || name == 'Appeals' -->
<button class="btn dropdown-toggle" data-toggle="dropdown"><span class="caret">/span>/button>
<!-- /ko -->
I am trying to show a button with a dropdown only when the name property contains the value "Setup" or "Appeals" but it does not work. Can we use logical operator in above knockout if binding ?
If the condition evaluates to true or true-like value, then the given HTML markup will be processed. Else, it will be removed from DOM. If the condition in the parameter contains an observable value, then the condition is re-evaluated whenever the observable value changes.
A binding context is an object that holds data that you can reference from your bindings. While applying bindings, Knockout automatically creates and manages a hierarchy of binding contexts. The root level of the hierarchy refers to the viewModel parameter you supplied to ko. applyBindings(viewModel) .
KO is able to create a two-way binding if you use value to link a form element to an Observable property, so that the changes between them are exchanged among them. If you refer a simple property on ViewModel, KO will set the form element's initial state to property value.
When you are using a conditional statement inside of your binding remember that you need to 'get' the value -
<!-- ko if: name() === 'Setup' || name() === 'Appeals' -->
<button class="btn dropdown-toggle" data-toggle="dropdown"><span class="caret">/span>/button>
<!-- /ko -->
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With