Skip to content

Instantly share code, notes, and snippets.

@evanshortiss
Last active October 8, 2015 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evanshortiss/7d601040606732747102 to your computer and use it in GitHub Desktop.
Save evanshortiss/7d601040606732747102 to your computer and use it in GitHub Desktop.
async.filter - An Example of an Asynchronous filter
// Assumes you've included the async library
var async = window.async
, userInput = $('input').val() // <== just an example, could use ng-model too in angular
, originalList = getTheHugeDataSetFromSomewhere()
, $scope.items = [];
async.filter(originalList, function (item, cb) {
// Check does the user input exist in the name
cb(item.name.indexOf(userInput) !== -1);
}, function (filteredItems) {
$scope.items = filteredItems;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment