L
L
LyoneNET2016-08-01 07:30:02
JavaScript
LyoneNET, 2016-08-01 07:30:02

How to delete multiple models in backbone?

Hello. Please tell me how can I remove several models from the collection. I do like this

addElement: function(el){
            if(this.collection.get(el.get('id')))
                this.collection.remove(el.get('id'));
            else
                this.collection.add(el);
            console.log(this.collection);
        }
....
....
....

_.each(this.collection.models, function(model){
                    model.destroy();
                });

but firstly, the models are partially deleted, secondly, the browser sends a delete request. But I need to remove some checked models from the collection. How to solve it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
aen, 2016-08-11
@aen

What does "partly" mean? If you don't want the browser to send a delete request, then don't call the `destroy` method on the model. It is just what is needed so that the model is deleted from the database, that is, it is completely destroyed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question