Server-side actions

Just as with Models, Collections have a fetch method that retrieves data from the server and a save method to send data to the server. One minor difference, however, is that by default, a Collection's fetch will merge any new data from the server with any data it already has. If you prefer to replace your local data with server data entirely, you can pass a {reset: true} option when you fetch. Collections also have the url, parse, and toJSON methods that control how fetch/save work.

All these methods work in the same way as they do on Models. However, Collections do not have urlRoot; while the Models inside a Collection may have IDs, the Collections themselves don't, so Collections don't need to generate their URLs using a .urlRoot:

var Cats = Backbone.Collection.extend({
     url: '/cats'
});
var cats = new Cats({name: 'Garfield'});
cats.save(); // saves Garfield to the server
cats.fetch(); // retrieves cats from the server and adds them
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.61.142