KO 1.3 template using comments

350 views
Skip to first unread message

Stefan

unread,
Sep 27, 2011, 9:32:53 AM9/27/11
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

Geert Pasteels

unread,
Sep 27, 2011, 3:03:34 PM9/27/11
to knock...@googlegroups.com
What is wrong with using comments? What do you use html comments for anyway? I am asking cause containerless control flow is like the only useful thing I ever did with html comments. 

Mark Bradley

unread,
Sep 27, 2011, 10:39:07 PM9/27/11
to knock...@googlegroups.com
comments are a great place to put random futurama quotes that will get
read more often than http headers.

--
-barkmadley
sent from an internet enabled device
http://barkmadley.com

alon...@gmail.com

unread,
Oct 22, 2012, 1:34:25 AM10/22/12
to knock...@googlegroups.com
This doesn't seem to be working with nammed templates
Reply all
Reply to author
Forward
0 new messages