Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

240
Visualizações
Jquery template - else if construct

I was trying to use an "else if" statement inside the jquery template block.I have seen in other samples that instead of writing if else, we can just put else.But this is not working for me, its throwing syntax error on the template.can any one help pls?

The acutual way it should work is like

if(Amount == "")
{
-
}
else if(balance == "")
{
*
}
else
{
Amount
}

I have mentioned below the jquery template syntax which i wrote to acheive this.

<script id="MyTemplate" type="text/x-jquery-tmpl">
    <tr style="background-color:#EFF3FB"><td onclick="test();">${CardNumber}</td><td>${PostDate}</td>
            <td>{{if (Amount == "")}}-
                {{else(balance == "")}}*                      
                {{else}}${Amount}
                {{/if}}
             </td>
             <td>${Description}</td></tr>
    </script>
over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

The syntax is correct as per JQuery API. Maybe try removing the '(' parentheses?

{{if Amount == ""}}
   -
{{else balance == ""}}
   *                      
{{else}}
   ${Amount}
{{/if}}
over 4 years ago · Santiago Trujillo Relatório

0

I had a similar issue when performing an if statement inside a loop, when doing the if statement on an item of the loop.

Assuming you are having an issue for the same reason (I see that your question includes some td and tr so you're probably iterating through items and displaying the their content in a table. Then here is my answer:

<script type="text/x-jquery-tmpl" id="jqTemplate">
 <ul>
      {{each data.messagetext}}
         <li>
             Message # ${$index+1}: &quot;${$value}&quot; |
             Test result: {{if $value}}exists{{else}}does not exist{{/if}}
         </li> 
      {{/each}}
    </ul>
</script>

notice the dollar sign in {{if $value}}, this is the trick on the regular {{if value}}

if you want to check the field of an item you are iterating on you can do {{if $value.fieldname}}exists{{else}}does not exist{{/if}}

fiddle http://jsfiddle.net/x2Tac/

jquery-template doc http://www.jquerysdk.com/api/template-tag-if

over 4 years ago · Santiago Trujillo Relatório

0

The correct answer is:

{{else [Condition]}}

Make sure that you import the jquery template js.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda