Answer the question
In order to leave comments, you need to log in
How to get element($el) from backbone collection element?
I iterate over the collection of models using _.each, I need to remove certain elements from the DOM. Each element (model) of the collection corresponds to a certain type. How to get this view and remove it from the DOM?
Answer the question
In order to leave comments, you need to log in
можно подписать вьюху на кастомное событие модели
var MyModel = Backbone.Model.extend({
initialize: function(){
//create MyView with {model:this}
}
});
var MyView = Backbone.View.extend({
initialize: function(options){
//your code
this.model.on('customEventName', this.remove);
}
});
var MyCollection = Backbone.Collection.extend({
model: MyModel
});
//go
var items = new MyCollection(arrayOfItems);
items.each(function(item){
if(item.get('someParam'))
item.trigger('customEventName');
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question