Closed doughsay closed 11 years ago
I'd rather not include that in the Repeat binding. One of the main advantages of this binding is its speed, which would be compromised by having to filter out array items.
It would be pretty easy to filter out the destroyed items yourself. Here's a function that does it:
function noDestroyed(array) {
return ko.utils.arrayFilter(ko.unwrap(array), function(item) {
return item == null || !ko.unwrap(item._destroy);
});
}
You could then bind using repeat like this:
<div data-bind="repeat: noDestroyed(myArray)">...</div>
Thanks, that does make sense. You could implement that function as a computed observable array as well, making the bind syntax look identical to if you were using a regular observable array.
If the collection you're iterating over is an object that has either a property or an observable property called
_destroy
set totrue
, it should not render that element.This is supported by default using the built-in foreach binding in knockout, so it seems to make sense to support it here.
See here for reference: http://knockoutjs.com/documentation/observableArrays.html#destroy_and_destroyall_note_usually_relevant_to_ruby_on_rails_developers_only