Jeremy Rosenberg
unread,Oct 27, 2011, 5:18:13 PM10/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
Basically, I have a table, and in the tbody, I have rows rendered from
an observableArray, plus an extra row not in that array but sometimes
using the same template.
To support this, I ended up using something along these lines:
<tbody>
<!-- ko template: { name: 'RowTemplate', foreach: ExistingItems } --
><!-- /ko -->
<!-- ko if: NewItem -->
<!-- ko template: { name: 'RowTemplate', data: NewItem } --><!-- /
ko -->
<!-- /ko -->
<!-- ko ifnot: NewItem -->
<tr><td colspan="x">Click here to add a new item</td></tr>
<!-- /ko -->
</tbody>
Is this kosher?
I can't use a data-bind attribute on tbody, because I need the
conditional logic for the "new" row after, still within tbody. There
is no element "in between" the tbody and tr's that I could stick a
data-bind attribute on. So it seems necessary to use containerless
bindings. However, all of the given containerless bindings use
anonymous templates except for the template binding. So that's what
I'm using.
I think it feels so hackish to me only because of the necessary
closing /ko comments after each template binding comment. There's no
body to them, and indeed there couldn't be, so it almost seems like
the template binding should be a self closing tag comment, but such a
thing doesn't exist right now.
Any thoughts?