Knockout Filtering on Observable Array

前端 未结 3 1082
天命终不由人
天命终不由人 2020-12-30 18:51

I\'ve started learning Knockout and I\'m having some trouble filtering an observable array on a button click and displaying the results.

This is my model:

         


        
3条回答
  •  青春惊慌失措
    2020-12-30 19:25

    You might want to have a look at Knockout Projections plugin from the author of original knockout. It has performance advantages in scenarios with large collections. See blogpost for more details.

    self.filterProducts = self.products.filter(function(prod) {
        return !self.currentFilter() || prod.genre == self.currentFilter();
    });
    

提交回复
热议问题