Friday, March 13, 2026
HomeLanguagesJavascriptBackbone.js save Model

Backbone.js save Model

In this article, we will see the Backbone.js save() model. The Backbone.js save() model is used to save the data of the given model by delegating the sync() method. Whenever the backbone is called, every time it reads & saves the model.

Syntax:

Backbone.Model.save(attributes, [options]);

Parameters: It accepts two parameter values:

  • attributes: It specifies the attribute in the model.
  • options: This parameter accepts attribute parameters like id etc.

Example 1: In this example, we are creating a model named “book” and applying the save() model.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <script src=
        type="text/javascript">
    </script>
    <script src=
        type="text/javascript">
    </script>
    <script src=
        type="text/javascript">
    </script>
</head>
  
<body>
    <script type="text/javascript">
        Backbone.sync = function (mymethod, mymodel) {
            document.write(mymethod + ": " 
            + JSON.stringify(mymodel) + "<br>");
  
        };
        var Books = Backbone.Model.extend();
        var book = new Books({ 
            bookid: 23, 
            price: 678, 
            book_name: "css" 
        });
  
        document.write(' Values: ' + JSON.stringify(book));
        document.write("<br>");
        book.save();  
    </script>
</body>
  
</html>


Output:

Values: {"bookid":23,"price":678,"book_name":"css"}
create: {"bookid":23,"price":678,"book_name":"css"}

Example 2: The following example demonstrates the save() model for empty “book” model data.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <script src=
            type="text/javascript">
    </script>
    <script src=
            type="text/javascript">
    </script>
    <script src=
            type="text/javascript">
    </script>    
</head>
  
<body>
    <script type="text/javascript"
      
        Backbone.sync = function(mymethod, mymodel) {  
           document.write(mymethod + ": " 
           + JSON.stringify(mymodel) + "<br>");  
        };  
        var Books = Backbone.Model.extend();  
        var book = new Books(); 
             
        document.write(' Values: ' + JSON.stringify(book)); 
        document.write("<br>");             
              
        book.save();  
    </script
</body>
</html>


Output:

Values: {}
create: {}

Reference: https://backbonejs.org/#Model-save

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

2 COMMENTS

Most Popular

Dominic
32506 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6882 POSTS0 COMMENTS
Nicole Veronica
12005 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12099 POSTS0 COMMENTS
Shaida Kate Naidoo
7011 POSTS0 COMMENTS
Ted Musemwa
7255 POSTS0 COMMENTS
Thapelo Manthata
6967 POSTS0 COMMENTS
Umr Jansen
6956 POSTS0 COMMENTS