CodesJava

Easy learning with example program codes

Backbone.JS Pop() collection


The Backbone.JS Pop() collection method is used to remove the models from the collection.

Syntax:

Backbone.Collection.Pop ( models, options )   

Parameters:
models: This parameter is used to specify the models to be removed from the collection.
options: This parameter is used to specify the model types.

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 num = Backbone.Model.extend({  
defaults: {  
number: 1   
}  });   
var X = Backbone.Collection.extend({  
model: num  
});  
var num1 = new num({number: 2});  
var num2 = new num({number: 3});  
var num3 = new num({number: 4});  
var numCollection = new X(); 
numCollection.push(num1);  
numCollection.push(num2); 
numCollection.push(num3); 
document.write('Number of numbers added: ' + numCollection.length); 
document.write("<br>");    
numCollection.pop(num1);          
document.write('Number of remaining numbers: ' + numCollection.length); 
</script>  
</body>  
</html>

Output:

Number of numbers added: 3
Number of remaining numbers: 2

Explanation:
In the above example, the Pop() method removes a model from the collection.

Please follow and like us:


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