开发者

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

开发者 https://www.devze.com 2023-02-15 12:11 出处:网络
I\'m using a jQuery template like so: <script type=\"text/html\" id=\"ListTemplate\"> {{if (parseInt($.attachment_count) > 0) }}

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

精彩评论

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

关注公众号