Reputation: 3417
I'm trying to generate a <select>
dropdown list of subclassifications to create a filter. When the list is generated I get duplicates and strings. How do I split the strings and then remove duplicates?
EXAMPLE - This is what I current get
<select data-filter="" class="form-control" name="subClassifications">
<option value="all">Select sub-classification</option>
<option value="Audit">Audit</option>
<option value="Assurance,Accounting,Audit">Assurance,Accounting,Audit</option>
</select>
Path: helper.js
subClassificationsFilter() {
let subClassifications = ProfessionalOverview.find( {}, { fields: { subclassification: 1 } } );
if ( subClassifications ) {
return _.uniq( subClassifications.map( ( subClassification ) => {
return subClassification.subclassification;
}), true );
}
},
Upvotes: 1
Views: 94
Reputation: 3417
subClassificationsFilter() {
let subClassifications = ProfessionalOverview.find( {}, { fields: { subclassification: 1 } } ).fetch();
let subClassification = _.map(subClassifications, function(obj) {
return obj.subclassification;
});
let groupSubClassification = _.flatten(subClassification);
return _.uniq(groupSubClassification).sort();
}
Upvotes: 0
Reputation: 958
Create a list to remove duplicates
unorderedList = Object.keys(myObject).map(function(key){
return {label: key, value: myObject[key]}
});
Then order the unordered list
const orderedList = {};
Object.keys(unorderedList).sort().forEach(function(key) {
orderedList[key] = unorderedList[key];
});
Use the ordered list to create your dropdown.
Upvotes: 3