CodesJava

Easy learning with example program codes

Backbone.JS Previous()


The Backbone.JS Previous() model is used to determine the previous value of the changed attribute of a model.

Syntax:

Model.Previous (attributes)   

Parameters:
attributes: This parameter is used to specify the properties of 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>  
</head>  
<body>  
<script type="text/javascript">  
var X = new Backbone.Model({  
msg1: "HELLO WORLD.",  
msg2: "Welcome."  
});  
X.set('msg1', 'Hello World.');  
document.write("Value of msg1 after set: ", JSON.stringify(X.changedAttributes()));  
document.write("<br>");  
document.write("Previous value of msg1: ", X.previous('msg1'));  
</script>  
</body>  
</html>

Output:

Value of msg1 after set: {"msg1":"Hello World."}
Previous value of msg1: HELLO WORLD.

Explanation:
In the above example, the msg1 vale has changed and thus the previous value is determined along with the changed value.

Please follow and like us:


Copyright © 2019 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki