Is there a 'else' construct for ko:if?

4,966 views
Skip to first unread message

Lane

unread,
Apr 21, 2014, 2:49:59 PM4/21/14
to knock...@googlegroups.com
If we using the <!--ko if: conditionX() --> syntax in a long loop and are running into performance issues. I think we could make the form a bit more peppy if we could cut down on one section where we draw out a lot of list items in a OL based on several conditions. Each of these conditions get checked in each loop when really there is only a need to check until the condition is met and then move on to the next iteration. Is there a syntax for 'else if'?

For example:

<!-- ko if: conditionX() -->
//something
<!-- ko: elseif conditionY() -->
//something else
<!-- ko elseif conditionZ() -->
//etc...
<!-- /ko -->

Baz

unread,
Apr 21, 2014, 3:40:32 PM4/21/14
to knockoutjs
I don't think anything besides:

<!-- ko if: conditionX() && !conditionY() && !conditionZ() -->
//something
<!-- /ko -->

<!-- ko if: !conditionX() && conditionY() && !conditionZ()) -->
//something else
<!-- /ko -->

<!-- ko if: @conditionX() && !conditionY() && conditionZ() -->
//etc...
<!-- /ko -->


--
You received this message because you are subscribed to the Google Groups "KnockoutJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to knockoutjs+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Lars GBN

unread,
Apr 21, 2014, 5:53:10 PM4/21/14
to knock...@googlegroups.com
Think again! Michael Best gives you...

https://github.com/mbest/knockout-switch-case

:-)

laneg...@gmail.com

unread,
Apr 22, 2014, 2:54:36 PM4/22/14
to knock...@googlegroups.com
That looks exactly like what I need. Thanks!

Baz

unread,
Apr 22, 2014, 3:22:57 PM4/22/14
to knockoutjs
Nice! hehe
Reply all
Reply to author
Forward
0 new messages