CodesJava

Easy learning with example program codes

Backbone.JS Fetch() collection


The Backbone.JS Fetch() collection method extracts the data from the model in a collection.

Syntax:

Collection.Fetch ( options )   

Parameters:
options: This parameter is used to specify the “SUCCESS” or “ERROR” callbacks.

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">  
Backbone.sync = function(method, model) {  
document.write("Fetched data: ",method + ": " + JSON.stringify(model));  
};   
var values = new Backbone.Collection({  
id:100,  
name:"Happy"  
});   
values.fetch();  
</script>  
</body>  
</html>

Output:

Fetched data: read: [{"id":100,"name":"Happy"}]

Explanation:
In the above example, the Fetch() method retrieves the data of the collection instance ‘values’.

Please follow and like us:


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