I have an observable array
var myArray = ko.observableArray([
{ name: "Jimmy", type: "Friend", Age: 30 },
{ name: "George", type: "Friend", Age: 40 },
{ name: "Zippy", type: "Enemy", Age: 20 }
]);
Now I want my output as
Friend Total Age: 70
Jimmy 30
George 40
Enemy Total Age : 20
Zippy 20
There is a similar jsfiddle link
If you want to keep with the generic structure (not just create computeds directly for “FriendTotalAge” and “EnemyTotalAge”), then you could expand the
distinctextension to include a property to use for the total.For example, you could pass in the name of the property that you want to use as a total and add a section in the extension like:
Now, your index could be by “type” and contain a computed total of the “age” property.
Update of the fiddle here: http://jsfiddle.net/rniemeyer/yrh5D/