我有一组"活跃的课程"当每个类变为活动状态时,它会被添加到我的数组中。我想进行数组测试,以确保每个类只在其中ONCE,然后将其文本作为li附加到dom。
var filtersArray = [],
activeFilters = state.activeFilter.replace('.', ' ');
//by default .mix and none is in activeFilters
//.hatch,.sedan,.suv get added later -> these are the only ones I want
// activeFilters really equals -> activeFilters = ['.mix','.hatch','.sedan','.suv'];
if (activeFilters != ".mix" || activeFilters != "none") {
if ($.inArray(activeFilters, filtersArray) == -1) {
filtersArray.push(activeFilters);
for (index = 0; index < filtersArray.length; ++index) {
//console.log(filtersArray[index]);
$('.filter-result-list').append('<li>' + filtersArray + '<i class="close">x</i></li>');
}
}
}