CodesJava

Easy learning with example program codes

Backbone.JS Pluck() collection


The Backbone.JS Pluck() collection method retrieves the attributes from a model in a collection.

Syntax:

Collection.Pluck ( attribute )   

Parameters:
attribute: This parameter is used to specify the attribute of a model in a collection.

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 names = new Backbone.Collection([  
{name: "Joy", id: 1},  
{name: "Happy", id: 2},  
{name: "Smiley", id: 3}  
]);    
document.write("Attributes returned on pluck: <br/>",names.pluck('name'));  
</script>  
</body>  
</html>

Output:

Attributes returned on pluck: 
Joy,Happy,Smiley

Explanation:
In the above example, the Pluck() method returns the “name” attributes from the model instances of a collection.

Please follow and like us:


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