I was working on a project today, that dealt with a large amount of JSON data.  The project needed to allow the user to filter the data by a bunch of different filters and options within those filters.

Initially I started using Underscore.js thinking this would help, but in the interest of time (had to get it done today!!!!) I decided to just do it quick and dirty.  Well, I succeeded in the dirty department:

[sourcecode lang=”javascript”]

if (filters.length > 0) {

for (var t = 0; t < d.resources[i].tags.length; t++) {

for (var f = 1; f < filters.length; f++) {

if (filters[f].type.toLowerCase() === d.resources[i].tags[t].ttype.toLowerCase()) {

if (filters[f].sels.length > 0) {

for (var s = 0; s < filters[f].sels.length; s++) {

var csel = filters[f].sels[s].toLowerCase();

for (y = 0; y < d.resources[i].tags[t].items.length; y++) {

if (d.resources[i].tags[t].items[y].toLowerCase() === csel)

matches[f] = true;

}

}

} else {

matches[f] = true;

}

}

}

}

} else {

for (var f = 0; f < filters.length; f++)

matches.push(true);

}

[/sourcecode]