Using the Knockout JS set visible: data-binding on items in an observable array. Is there a way I can get a count in Knockout JS of the number of items specifically with the visible data-binding = true?
I tried something like this (not working):
var visibleItems = ko.utils.arrayFilter(self.MyItems(), function(item) {
return item.visible == true;
});
var result = visibleItems().length;
In this test, item.visible is undefined. That's what I'm looking for, how can I get to Knockout JS' visible status property value that corresponds to their "data-bind=visible:" Is that accessible somewhere within item?
item.visible
anobservable
or just a regular property (i.e. do you needitem.visible() == true
)? – MarkvisibleItems
computed array on your root view model and bind to that, instead of showing all the items and setting the visible binding for each one. Then its length will always match the number of items being displayed. – Mark