开发者

jQuery Template, {{if}} with a passed string

I'm using a jQuery template like so:

<script type="text/html" id="ListTemplate">
{{if (parseInt($.attachment_count) > 0) }}
    XXXX
{{else}}
    ${attachment_count}
{{/if}}

</script>

But this does not work? The if block never returns true开发者_JS百科. Any suggestions? thanks


I don't think the parenthesis are necessary, but they shouldn't cause any issues. Maybe there's an issue with your code inside the {{if}} block?

Should

{{if (parseInt($.attachment_count) > 0) }}

be:

{{if (parseInt(attachment_count) > 0) }}

Where attachment_count is a property of the object the template is rendering?

Additionally, you can actually write console statements in jQuery templates:

${console.log($item)}

The template engine will render undefined on your template, but you'll be able to inspect template variables through the console. This can be helpful because sometimes those templates can be difficult to debug.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜