JS数组输出麻烦

时间:2014-08-11 21:39:32

标签: javascript arrays string for-loop

我有一组"活跃的课程"当每个类变为活动状态时,它会被添加到我的数组中。我想进行数组测试,以确保每个类只在其中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>');
    }

}
}

jsFiddle:http://jsfiddle.net/im_cr/8zyhhftL/11/

0 个答案:

没有答案