CodesJava

Easy learning with example program codes

Backbone.JS Where() collection


The Backbone.JS Where() collection method is used to display the model by using the matched attribute in the collection.

Syntax:

Collection.Where ( 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: 10},  
{name: "Joy", id: 30},  
{name: "Smiley", id: 20}  
]);    
var X = names.where({name: "Joy"});  
document.write("Total matched name attribute:", + X.length);    
</script>  
</body>  
</html>

Output:

Total matched name attribute:2

Explanation:
In the above example, the Where() method returns the number of matched value for the “name” attributes of the models in a collection.

Please follow and like us:


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