The Backbone.JS Sync() collection method is used to specify the state of the model and to display the state of the collection.
Syntax:
Backbone.Collection.Sync ( method, collection, options )
Parameters:
method: This parameter is used to specify the CRUD operations: create, read, update and delete.
collection: This parameter is used to specify the collection containing a set of models.
options: This parameter is used to specify the success or error messages.
Example:
Example
Output:
Model state: read: [{"name":"Tom","age":20}]
Explanation:
In the above example, sync() method reads and fetches the model data while the fetch() method display the model’s state by delegating the sync() method.