Assuming that items
will be updated while the application is running:
var model = {};
model.items = ko.observable([1,2,3,4,5,6]);
model.renderedItems = ko.computed(function() {
var data = model.items();
var times = Math.ceil(items.length / 3);
var result = [];
for (var i = 0; i < times; i ++) {
result.push(data.slice(i * 3, i * 3 + 3));
}
return result;
});
Now bind renderedItems
to a template that will have two nested foreach
bindings.