I can't figure out how to work with iterations in foreach of KOjs. What I need is to group contents of an array like this
Var x = [{name: Joel, sex: male}, {name: Eric, sex: male},{name:Elliot, sex:female}, {name:Mary, sex:female}]
So the resulting data-bind foreach would display the sex of the person, but only once as a label. Something like this
-male
Joel
Eric
-female
Elliot
Mary
With normal for loops it is as simple as making a variable that holds last entry's gender, and prints the new one if it changes. Something like
If(this.sex != cachedSex){
cachedSex=this.sex;
console.log(cachedSex);
}
But I can't figure it out how to make this in KO.js Please give me an advice.