How to use nested if in style css Lightning Design System. this is working fine

<div class="{!v.case.Priority == 'Closed' 
                     ? 'row closed' : 'row '}" >

But when I write the same for nested if condition it doesn't work

<div class="{!v.case.Priority == 'Closed' 
                 ? 'row closed' : v.case.Priority == 'New' 
                 ? 'row new' : 'row '}" >
  • If you don't find a solution to your code, you could try adding a wrapper and instead of doing v.case.Priority do v.caseWrapper.parsedPriority. – D. Cruz Aug 2 '16 at 23:10
  • 1
    Do parentheses help i.e. v.case.Priority == 'Closed' ? 'row closed' : (v.case.Priority == 'New' ? 'row new' : 'row ')? – Keith C Aug 2 '16 at 23:27

If you can't nest the terniary operator, then concatenate two (or more) of them. Try something like this:

"{! v.case.Priority == 'Closed' ? 'row closed' : '' + 
   v.case.Priority == 'New' ? 'row new' : 'row ' }"

One other option (which I haven't tried) would be to use the function version of the terniary operator - if(condition, true, false) and see if that is able to be nested.

Reference here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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