I think this is the intent of this method but I’m struggling to get it to work.
I have a method to change selectedFilterLabel based on a selection, but when I change it, the condition in the where doesn’t trigger it to run again. Accoring to the documentation, it should process the where again if the condition contains an Observable. In this example, selectedFilterLabel is an Observable.
Initially, I’m filtering to only seeing items with a food category, and that works. Then when I change it to coffee, it’s not updating. Is there a different way I should be triggering it?
JS:
function Card(title, categories) {
this.title = title;
this.categories = categories;
}
var cardList = Observable(
new Card("Test 1", Observable("food", "coffee")),
new Card("Test 2", Observable("coffee", "other"))
);
var selectedFilterLabel = Observable("food");
var filteredCardList = cardList.where(function(e) { return e.categories.contains(selectedFilterLabel.value);
});
function filterView(args) {
selectedFilterLabel.value = args.data.filterLabel;
}
But I found a strange things. I have a strings array in my original Observable. And I use the user’s key in string to filter this array. The view list items will change and narrow while the use key in. But I found that if I keys in the backspace, the filter arrange will expand. but the items display order will change not like the original one. The items that fit the previous search value display on the top.