jquery - Using an If condition inside a template -
how use if
statement inside of jquery template?
here's template:
<script type="text/html" id="attachmentlisttemplate"> {{if $item.current_cmt_id == id }} <li> <a href="${link}" class="fancyiframe clearfix">${title}</a> </li> {{/if}} </script>
where id ${id}
, being passed data binding (via knockoutjs). without if statement outputs fine, so: ${$item.current_cmt_id}
here data-binding (powered knockoutjs):
<ul data-bind='template: { name: "attachmentlisttemplate", foreach: attachmentsmodel.convattachments, templateoptions: {current_cmt_id: <%=comment.id%>} }'> </ul>
any suggestions why if sttatement not working? comparing 2 conditions correctly?
assuming id
observable, need invoke function rather treat property. try following:
{{if $item.current_cmt_id == id()}}
Comments
Post a Comment