How can I access View's element that related to Model's object?
For example, I have a collection of Products. Each product has color property. I'd like to "hide" (i.e. remove View representation) every product whose color equals to "red".
The only way I know so far is through invoking (for examle) destroy() method of Model's object (the code below). But I don't want to destroy Model's object. Is it possible to remove View's element without changing its Model?
// App
hide_red_products: function() {
Product.each(function(x) {
if (x.attributes.color == "red") { x.destroy() }
})
}
// Products' view
initialize: function() {
this.model.bind('destroy', this.remove_element, this);
}
remove_element: function() {
return $(this.el).remove();
}