我正在尝试生成<select>
子类别下拉列表以创建过滤器。生成列表时,我得到重复项和字符串。如何拆分字符串然后删除重复项?
示例 - 这是我目前获得的
<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>
路径:helper.js
subClassificationsFilter() {
let subClassifications = ProfessionalOverview.find( {}, { fields: { subclassification: 1 } } );
if ( subClassifications ) {
return _.uniq( subClassifications.map( ( subClassification ) => {
return subClassification.subclassification;
}), true );
}
},
答案 0 :(得分:3)
创建列表以删除重复项
unorderedList = Object.keys(myObject).map(function(key){
return {label: key, value: myObject[key]}
});
然后订购无序列表
const orderedList = {};
Object.keys(unorderedList).sort().forEach(function(key) {
orderedList[key] = unorderedList[key];
});
使用有序列表创建下拉列表。
答案 1 :(得分:0)
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();
}