0

I have template this a part:

<td>{{=name}}</td>]

I need check name of null/empty and not display it.

How do this?

example:

{{#if ($name!= "" && $secondName!= "") }}

I get error Uncaught SyntaxError: Unexpected token &&

4

3 に答える 3

1

If you are using jsrender then

{{if name}}

should do the trick

You can find a lot of scenarios solved in the jsrender demo section.

于 2013-01-30T10:11:01.950 に答える
1

you can use if(name && name !='' ) for more Security !!

于 2013-01-30T10:15:22.197 に答える
0

Are you using an out-of-date version of JsRender? The syntax is {{:name}}, and it automatically renders an empty string is name is undefined or null. Unit test here: https://github.com/BorisMoore/jsrender/blob/master/test/unit-tests/tests-jsrender-no-jquery.js#L108

With the latest version you can even write {{:a.b.c.name noerror=true}} and it will render the empty string even if any of name, or a.b.c or a.b or a are undefined or null.

You don't need to wrap in an {{if ...}}...{{/if}}

于 2013-01-31T17:50:25.473 に答える