开发者

jquery tmpl with if else

I'm trying to cache my markup into a $.template. Inside of that, I'd like to add a conditional where, if a variable is empty, the output is reflected with this.

Here is a snippet of my attempt. When I run this, the event type is either correct, or blank. "(No Moderators Listed)" never shows up.

What am I doing wrong?

var markup = '<div class="new_line general_head开发者_如何学Cing">' +
                 '{{if EventType != ""}}' +
                     '${$EventType}' +
                 '{{else}}' +
                     '(No Moderators Listed)' +
                 '{{/if}}' +
             '</div>' +
             '<div class="gray_rule allclear"></div>';


There's a small error in your template that could be causing issues:

var markup = '<div class="new_line general_heading">' +
                 '{{if EventType != ""}}' +
                     '${EventType}' +
                 '{{else}}' +
                     '(No Moderators Listed)' +
                 '{{/if}}' +
             '</div>' +
             '<div class="gray_rule allclear"></div>'

Changed ${$EventType} to ${EventType}. After that change, the template seems to work fine.

Example: http://jsfiddle.net/tx97s/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜