categoryId . :
HTML:
<table>
<tbody data-bind="foreach: items">
<tr class="category">
<td colspan="2" data-bind="text: item"></td>
</tr>
<tr>
<td data-bind="text: item"></td>
<td class="num" data-bind="text: quantity"></td>
</tr>
</tbody>
</table>
ViewModel:
function Item(type, categoryId, item, quantity) {
this.type = type;
this.categoryId = categoryId;
this.item = ko.observable(item);
this.quantity = ko.observable(quantity);
}
var vm = {
items: ko.observableArray([
new Item(0, 1, "Fruit"),
new Item(1, 1, "Apples", 27),
new Item(1, 1, "Oranges", 17),
new Item(1, 1, "Kiwis", 3),
new Item(0, 2, "Vegetables"),
new Item(1, 2, "Celery", 16),
new Item(1, 2, "Carrots", 72),
new Item(0, 3, "Sundries"),
new Item(1, 3, "Toothpaste", 10),
new Item(1, 4, "Washing-up liquid", 8)
])
};
ko.applyBindings(vm, document.body);