Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

241
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

0

The correct answer is:

{{else [Condition]}}

Make sure that you import the jquery template js.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda