这篇文章对我帮助很大,所以我想我会在这里添加它,以防其他人尝试做我所拥有的。
首先是 list.js 的 JS:
/*
* Filtering
*/
var options = {
valueNames: ['name','phone','status','street','tier','type','zip','zone'],
plugins: [
['fuzzySearch']
]
}
var featureList = new List('directory-list', options)
$('.search-fuzzy').keyup(function(){
featureList.fuzzySearch($(this).val());
});
$('#filter-select').on('click', 'a.filters', function(e){
if(this.id == 'filter-type-any' || this.id == 'filter-status-any' || this.id == 'filter-zone-any'){
$(this).addClass('active').parent().siblings().children().removeClass('active')
} else {
$(this).toggleClass('active')
$(this).parent().parent().find('.any').removeClass('active')
}
var activeFilters = []
$('#filter-select').find('a.active').each(function(i) {
if (this.getAttribute('data-match')){
activeFilters.push(this.getAttribute('data-match'))
}
})
if(activeFilters.length) {
var anyType = (($.inArray('resident', activeFilters) + $.inArray('business', activeFilters) + $.inArray('school', activeFilters)) == -3) ? true : false;
var anyStatus = (($.inArray('current', activeFilters) + $.inArray('expiring', activeFilters) + $.inArray('expired', activeFilters) + $.inArray('never', activeFilters)) == -4) ? true : false;
var anyZone = (($.inArray('zone1', activeFilters) + $.inArray('zone2', activeFilters) + $.inArray('zone3', activeFilters) + $.inArray('zone4', activeFilters) + $.inArray('zone5', activeFilters) + $.inArray('zone6', activeFilters) + $.inArray('zone7', activeFilters) + $.inArray('zone8', activeFilters)) == -8) ? true : false;
featureList.filter(function(item) {
if (
( anyType || ($.inArray(item.values().type.toLowerCase(), activeFilters) > -1) )
&&
( anyStatus || ($.inArray(item.values().status.toLowerCase(), activeFilters) > -1) )
&&
( anyZone || ($.inArray(item.values().zone.toLowerCase(), activeFilters) > -1) ) )
{
return true;
} else {
return false;
}
})
} else {
featureList.filter()
}
})
目录过滤器控件
#directory-filters
.row-fluid
input.search-fuzzy(placeholder='Search')
#filter-select.row-fluid
.span6
h5 Type
ul#filter-type
li
a#filter-type-any.filters.any.active(href='#') All Entries
li
a#filter-type-people.filters(href='#', data-match='resident') People
li
a#filter-type-business.filters(href='#', data-match='business') Business
li
a#filter-type-schools.filters(href='#', data-match='school') Schools
br
h5 Status
ul#filter-status
li
a#filter-status-any.filters.any.active(href='#') Any Status
li
a#filter-status-member.filters(href='#', data-match='current') Members
li
a#filter-status-expiring.filters(href='#', data-match='expiring') Expiring
li
a#filter-status-expired.filters(href='#', data-match='expired') Expired
li
a#filter-status-never.filters(href='#', data-match='never') Never Member
.span6
h5 Zone
ul#filter-zone
li
a#filter-zone-any.filters.any.active(href='#') All Zones
li
a#filter-zone-1.filters(href='#', data-match='zone1') Zone 1
li
a#filter-zone-2.filters(href='#', data-match='zone2') Zone 2
li
a#filter-zone-3.filters(href='#', data-match='zone3') Zone 3
li
a#filter-zone-4.filters(href='#', data-match='zone4') Zone 4
li
a#filter-zone-5.filters(href='#', data-match='zone5') Zone 5
li
a#filter-zone-6.filters(href='#', data-match='zone6') Zone 6
li
a#filter-zone-7.filters(href='#', data-match='zone7') Zone 7
li
a#filter-zone-8.filters(href='#', data-match='zone8') Zone 8