Sync

Other topics

Basic Example

The sync() method reads and fetched the model data

     Backbone.sync = function(method, model) {
        document.write("The state of the model is:");
        document.write("<br>");

        //The 'method' specifies state of the model
        document.write(method + ": " + JSON.stringify(model));
     };

     //'myval' is a collection instance and contains the values which are to be fetched in the collection
     var myval = new Backbone.Collection({
        site:"mrfarhad.ir",
        title:"Farhad Mehryari Official Website"
     });

     //The myval.fetch() method displays the model's state by delegating to sync() method
     myval.fetch();

this code will outputs :

The state of the model is:
read: [{"site":"mrfarhad.ir","title":"Farhad Mehryari Official Website"}]

Syntax:

  • sync(method, model, options)

Parameters:

parameterdetails
methodcreate , read , update , delete
modelthe model to be saved (or collection to be read)
optionssuccess and error callbacks, and all other jQuery request options

Contributors

Topic Id: 8178

Example Ids: 26283

This site is not affiliated with any of the contributors.