【发布时间】:2011-07-03 04:38:56
【问题描述】:
如何在 jQuery 模板中使用 IF 语句?
这是我的模板:
<script type="text/html" id="attachmentListTemplate">
{{if $item.current_cmt_id == id }}
<li>
<a href="${link}" class="fancyIFrame clearfix">${title}</a>
</li>
{{/if}}
</script>
其中 id 本质上是 ${id} 并且由数据绑定传递(通过 KnockoutJS)。没有 IF 语句的输出很好,如下所示:${$item.current_cmt_id}
这是数据绑定(由 KnockoutJS 提供支持):
<ul data-bind='template: { name: "attachmentListTemplate", foreach: attachmentsModel.convAttachments, templateOptions: {current_cmt_id: <%=comment.id%>} }'> </ul>
关于为什么 if 语句不起作用的任何建议?我是否正确比较了这两种情况?
【问题讨论】:
-
您也使用服务器端语言吗?如果是这样,源是否显示整数? (因为 我问...)
-
是的,它会在浏览器中呈现为 INT,111
标签: jquery knockout.js jquery-templates