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?

7ochem
  • 7,532
  • 14
  • 51
  • 80
Dhaduk Mitesh
  • 1,675
  • 1
  • 11
  • 29

2 Answers2

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.

Dhaval Solanki
  • 2,416
  • 3
  • 23
  • 41
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

Prashant Valanda
  • 12,659
  • 5
  • 42
  • 69