CodesJava

Easy learning with example program codes

Backbone.JS Save()

The Backbone.JS Save() model is used to read and save the data of the model every time when it is called.

Syntax:

Model.Save (attributes, options)

Parameters:
attributes: This parameter is used to specify the properties of a model.
options: This parameter is used to specify the options like id, name etc. for a model.

Example:

<!DOCTYPE html>  
<html>
<head>  
<title>Example</title>  
<script src="https://code.jquery.com/jquery-2.1.3.min.js" type="text/javascript"></script>  
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.2/underscore-min.js" type="text/javascript"></script>  
<script src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.2/backbone-min.js" type="text/javascript"></script>  
<script type="text/javascript">  
var details = new Backbone.Model({  
msg1: "HELLO WORLD.",  
msg2: "Welcome."  
});  
Backbone.sync = function(method, model) {  
document.write(method + ": " + model.get('msg1')+ " " +model.get('msg2'));  
model.set('id', 100);  
};  
details.save();  
document.write("<br>");  
details.save({msg1 : "Hello World."});  
</script>  
</head>  
</html>

Output:

create: HELLO WORLD. Welcome.
update: Hello World. Welcome.

Explanation:
In the above example, the properties of a model are created, updated and saved.

Please follow and like us:
error









Copyright © 2019 CodesJava DMCA.com Protection Status