var article_data = [{
id: 1,
title: "Fearing midterm turnout, Jedis embrace dark side.",
authors: ["person-a", "person-b"],
topics: ["politics", "religion"]
}, {
id: 2,
title: "We used the force to clean our apartment, you won't believe what happened next.",
authors: ["person-b", "person-c"],
topics: ["religion"]
}, {
id: 3,
title: "Can ewoks use the force? Jedi council debates.",
authors: ["person-c"],
topics: ["race", "religion"]
}]
var collection = new PourOver.Collection(article_data);
var topicsFilter = PourOver.makeInclusionFilter("topics", ["race", "religion", "politics"]);
var authorsFilter = PourOver.makeInclusionFilter("authors", ["person-a", "person-b", "person-c"]);
// We'll populate this with cids from our text inputting via Bloodhound
var textSearchFilter = PourOver.makeManualFilter("title")
collection.addFilters([topicsFilter, authorsFilter, textSearchFilter]);
var view = new PourOver.View('default_view', collection);
printResults();
// Grab everything and store it
// We'll feed this to Bloodhound
// Grab a list of all cids to pass when we want to
var base_view = view.getCurrentItems(),
all_cids = _.pluck(base_view, 'cid');
$('input[type="checkbox"]').on('change', function () {
var $this = $(this),
filter_group = $this.parents('ul').attr('data-group'),
value = $this.val(),
checked = $this.prop('checked') == true;
//console.log(filter_group, value, checked);
// If it's checked set the query to the value of this tag
if (checked) {
collection.filters[filter_group].intersectQuery(value);
} else {
// If it's not checked then clear the query from the PourOver match set.
collection.filters[filter_group].removeSingleQuery(value);
}
printResults();
});
// Set up bloodhound
// https://github.com/twitter/typeahead.js/blob/master/doc/bloodhound.md
var engine = new Bloodhound({
name: 'articles',
local: base_view,
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.