Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle if/else statement in knockout container less form?

Tags:

knockout.js

Is this possible to have if-else statement when using knockout container less statements? I mean Something like:

<!-- ko else --> 
like image 345
xpollcon Avatar asked Apr 01 '14 01:04

xpollcon


People also ask

How do you write if condition in knockout?

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.

What happens in if binding?

The if binding causes a section of markup to appear in your document (and to have its data-bind attributes applied), only if a specified expression evaluates to true (or a true -ish value such as a non- null object or nonempty string).

What is KO in knockout JS?

KO is that it updates your UI automatically when the view model changes.

Why knockout JS is used?

Knockout. js is a minimalist JavaScript framework for web application development. It is a JavaScript library that allows binding HTML elements against any data model. It is primarily used for creating rich and responsive display as well as editor user interfaces with a clean, underlying data model.


1 Answers

As mentioned, there isn't an else, but it's common to combine ko if and ko ifnot using the same flag.

<!-- ko if: myFlag -->     ...some stuff for the true case <!-- /ko --> <!-- ko ifnot: myFlag -->     ...some stuff for the else (false) case <!-- /ko --> 
like image 96
Joseph Gabriel Avatar answered Sep 22 '22 10:09

Joseph Gabriel