CodesJava

Easy learning with example program codes

Backbone.JS Changed()

The Backbone.JS Changed() model is used to change all the attributes that have been set by using set() method.

Syntax:

Model.Changed   

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">  
X = Backbone.Model.extend({  
defaults: {  
msg: 'HELLO WORLD',  
type: 'Acknowledge'  
},  
initialize: function () {  
this.bind("change:msg", function (model) {  
var msg2 = model.get("msg");  
var type2 = model.get("type");  
});  
}  
});  
var Y = new X();  
document.write("<b>Original Message:</b> ", Y.get("msg"));  
Y.set({ msg: 'WELCOME ALL' });  
document.write("<br><b>Changed Message:</b> ", Y.get("msg"));  
</script>  
</head>   
</html>

Output:

Original Message: HELLO WORLD
Changed Message: WELCOME ALL

Explanation:
Here the msg attribute of a model is Changed.

Please follow and like us:
error









Copyright © 2019 CodesJava DMCA.com Protection Status