resetcollection.reset([models], [options])
Adding and removing models one at a time is all well and good, but sometimes you have so many models to change that you'd rather just update the collection in bulk. Use reset to replace a collection with a new list of models (or attribute hashes), triggering a single "reset"
event on completion, and without triggering any add or remove events on any models. Returns the newly-set models. For convenience, within a "reset"
event, the list of any previous models is available as options.previousModels
.
Pass null
for models
to empty your Collection with options
.
Here's an example using reset to bootstrap a collection during initial page load, in a Rails application:
<script> var accounts = new Backbone.Collection; accounts.reset(<%= @accounts.to_json %>); </script>
Calling collection.reset()
without passing any models as arguments will empty the entire collection.
Please login to continue.