Skip to content

Instantly share code, notes, and snippets.

@houoop
Created January 9, 2013 09:17
Show Gist options
  • Save houoop/4491794 to your computer and use it in GitHub Desktop.
Save houoop/4491794 to your computer and use it in GitHub Desktop.
observableArray filter prototype extend
ko.observableArray.fn.filterByProperty = function(propName, matchValue) {
return ko.computed(function() {
var allItems = this(), matchingItems = [];
for (var i = 0; i < allItems.length; i++) {
var current = allItems[i];
if (ko.utils.unwrapObservable(current[propName]) === matchValue)
matchingItems.push(current);
}
return matchingItems;
}, this);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment