Stefan
unread,Sep 27, 2011, 9:32:53 AM9/27/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to KnockoutJS
Hi,
regarding templates using comments:
<ul>
<li>First static item</li>
<!-- ko foreach: items -->
<li data-bind="text: name"></li>
<!-- /ko -->
</ul>
As I understand, the reason for this feature is to be able to insert
static items (or possibly from different arrays).
I must say that I don't quite like putting anything but comments
inside the comments. I think the best way to handle this would be to
have a special parameter for the foreach binding so that the container
element is removed from the result DOM and only its child is
replicated. Something like this:
<ul>
<li>First static item</li>
<someElement data-bind="foreach: items, removeMe">
<li data-bind="text: name"></li>
</someElement>
</ul>
Unfortunatelly it seems that the only thing you can put in any place
is a comment (that's why I guess they were used in the first place).
But how about a binding that would clone the element?
<ul>
<li>First static item</li>
<li data-bind="cloneForeach: items, text: name"></li>
</ul>
What do you think about this approach?
Stefan