javascripthtmlbackbone.js

Using javascript template file, how can I check for a null or an undefined value?


I am using a Javascript HTML template engine. How do I check for null or undefined in my HTML?

If ctx.m.transferTicket is null or undefined, I want to treat that as being false.

SO I have this code

{% if (ctx.m.transferTicket===false || ctx.m.transferTicket=='') { %}
    <div>NOT TRANSFERRED</div>

{% } else { %}
    <div>TRANSFERRED</div>
{% } %}

But if ctx.m.transferTicket is null or undefined, it acts as if it's true.

How can I fix this?

Thanks!


Solution

  • Have you tried it like this?

    {% if (ctx.m.transferTicket) { %}
        <div>TRANSFERRED</div>
    
    {% } else { %}
        <div>NOT TRANSFERRED</div>
    {% } %}