Winkel js Entfernen von doppelten Schlüsselfeld aus allen Arrays innerhalb eines Arrays
app.filter('unique', function() {
return function(collection, keyname) {
var output = [],
keys = [];
angular.forEach(collection, function(item) {
var key = item[keyname];
if(keys.indexOf(key) === -1) {
keys.push(key);
output.push(item);
}
});
return output;
};
});
/* mainOptions = [ a1[],b2[],c3[]]
subOptions a1[] = [fuzzyoptions{ optionid : 11},fuzzyoptions{ optionid : 13},fuzzyoptions{ optionid : 11},fuzzyoptions{ optionid : 12}]
subOptions b1[] = [fuzzyoptions{ optionid : 12},fuzzyoptions{ optionid : 13},fuzzyoptions{ optionid : 11},fuzzyoptions{ optionid : 12}]
subOptions b1[] = [fuzzyoptions{ optionid : 19},fuzzyoptions{ optionid : 23},fuzzyoptions{ optionid : 11},fuzzyoptions{ optionid : 12}] */
/* I want ng-repeat to remove duplicates for optionid in all arrays inside one main array */
/*so check will go for fuzzyoptions{ optionid : 11},fuzzyoptions{ optionid : 13},fuzzyoptions{ optionid : 12},fuzzyoptions{ optionid : 19},fuzzyoptions{ optionid : 23} only 5 times*/
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js"></script>
<div ng-repeat = "main in mainOptions">
<div ng-repeat = "sub in main.SubOptions | unique: 'sub.fuzzyoptions.optionid'">
</div>
</div>
I doppelte optionids Feld entfernt werden soll; s Werte von allen Suboption Arrays innerhalb mainOptions Arrays. Ich möchte erreichen, doppelte Schlüssel-Wert-Felder für alle Arrays in einem Eltern-Array mit benutzerdefinierten Filter oder verfolgen durch oder jede andere Lösung mit Winkel js