0

I want to add a condition if...elseif...else in a knockout HTML file.

I tried to add the condition like this,

<!-- ko if: condition 1 -->
    [...]
<!-- /ko -->
<!-- ko elseif: condition 2 -->
    [...]
<!-- /ko -->
<!-- ko else -->
    [...]
<!-- /ko -->

I know how to add if...elseif and if...notif. But I do not have the idea about this if...elseif...else condition.

Does anyone have the idea about this?

4

2 Answers 2

0

There is no elseif. If you need else if you need to include other library see the reference

You can use below workaround for if else

enter image description here

0

I have one alternative logic for you. Take one flag variable. with that you can do this easily. Below is not actual code but it shows the logic of alternative way for doing this.

<!-- ko if: condition 1 -->
    [...](if this condition true make flag=true)
<!-- /ko -->

<!-- ko elseif: condition 2 -->
    [...](if this condition true make flag=true)
<!-- /ko -->

<!-- ko if: condition 3 --> (In condition 3 check if flag == false then do your stuff) 
    [...]
<!-- /ko -->

This one alternative solution or logic that you can implement to complete your requirement.

1
  • var flag=false; not possible in html file. Apr 6, 2018 at 11:45

Not the answer you're looking for? Browse other questions tagged or ask your own question.