I know that I can use the comment foreach
in knockout to add conditions to lists. But I would like to add a default row to the table if the observableArray
is empty.
Currently I do something like this:
<table>
<!-- ko foreach: members -->
<tr>
<td data-bind="text: Id"></td>
<td data-bind="text: FirstName"></td>
<td data-bind="text: LastName"></td>
</tr>
<!-- /ko -->
<tr data-bind="if: MemberCount == 0">
<td colspan="3">
No members have been added yet
</td>
</tr>
</table>
Is there a more elegant way?