- BackboneJS - Utility
- BackboneJS - View
- BackboneJS - Sync
- BackboneJS - History
- BackboneJS - Router
- BackboneJS - Collection
- BackboneJS - Model
- BackboneJS - Events
- BackboneJS - Applications
- BackboneJS - Environment Setup
- BackboneJS - Overview
- BackboneJS - Home
BackboneJS Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
BackboneJS - Collection
Collections are ordered sets of Models. We just need to extend the backbone s collection class to create our own collection. Any event that is triggered on a model in a collection will also be triggered on the collection directly. This allows you to psten for changes to specific attributes in any model in a collection.
The following table psts down all the methods which you can use to manipulate the BackboneJS-Collection −
S.No. | Methods & Description |
---|---|
1 |
Extends the backbone s collection class to create a collection. |
2 |
To specify the model class, we need to override the model property of the collection class. |
3 |
When a model instance is created, it is invoked by defining the initiapze function when the collection is created. |
4 |
Array of models which are created inside the collection. |
5 |
Returns the copy of the attributes of a model using the JSON format in the collection. |
6 |
It represents the state of the model and uses the Backbone.sync to display the state of the collection. |
7 |
Add a model or array of models to the collection. |
8 |
Removes a model or array of models from the collection. |
9 |
It resets the collection and populates with new array of models or will empty the entire collection. |
10 |
It is used to update the collection with a set of items in a model. If any new model is found, the items will be added to that model. |
11 |
It is used to retrieve the model from a collection by using the idor cid. |
12 |
Retrieve the model from a collection by using specified index. |
13 |
It is similar to the add() method which takes the array of models and pushes the models to the collection. |
14 |
It is similar to the remove() method which takes the array of models and removes the models from the collection. |
15 |
Add a specified model at the beginning of a collection. |
16 |
It removes the first item from the collection. |
17 |
Displays the shallow copy of the elements from the collection model. |
18 |
Counts the number of models in the collection. |
19 |
It is used to sort the items in the collection. |
20 |
Sorts the items in the collection and uses comparator property in order to sort the items. |
21 |
Retrieves the attributes from the model in the collection. |
22 |
It is used to display the model by using the matched attribute in the collection. |
23 |
It returns the model, that matches the specified attribute in the collection. |
24 |
It creates an instance of the collection and returns where resources are located. |
25 |
Returns the collection s data by passing through the response object and represents the data in JSON format. |
26 |
It returns the shallow copy of the specified object. |
27 |
It extracts the data from the model in the collection using the sync method. |
28 |
It creates a new instance of the model in the collection. |
Underscore Methods
The following table psts down the Underscore.js methods which provides their functionapty to be used on the Backbone.Collection.
S.No. | Methods & Description |
---|---|
1 |
_.each(pst, iteratee, [context]) Iterates each of the elements in the collection using the iteratee function. |
2 |
_.map(pst, iteratee, [context]) It maps each value and displays them in a new array of values using the iteratee function. |
3 |
_.reduce(pst, iteratee, memo, [context]) It reduces the pst of values into a single value and it also known as inject and foldl. |
4 |
_.reduceRight(pst, iteratee, memo, [context]) It is the right associative version of reduce. |
5 |
_.find(pst, predicate, [context]) It finds each value and returns the first one which passes the predicate or test. |
6 |
_.filter(pst, predicate, [context]) It filters each value and returns the array of values which passes the predicate or test. |
7 |
_.reject(pst, predicate, [context]) It returns the rejected elements in the pst which do not pass the predicted values. |
8 |
_.every(pst, predicate, [context]) It returns true, if elements in the pst pass the predicted values. |
9 |
_.some(pst, predicate, [context]) It returns true, if elements in the pst pass the predicted values. |
10 |
_.contains(pst, value, [fromIndex]) It returns true, if a value is present in the pst. |
11 |
_.invoke(pst, methodName, *arguments) It invokes the method name using methodName() on each value in the pst. |
12 |
_.max(pst, [iteratee], [context]) It specifies the maximum value in the pst. |
13 |
_.min(pst, [iteratee], [context]) It specifies the minimum value in the pst. |
14 |
_.sortBy(pst, [iteratee], [context]) It returns the sorted elements in the ascending order by using iteratee in the pst. |
15 |
_.groupBy(pst, [iteratee], [context]) It spanides the collection values into the sets, grouped by using the iteratee in the pst. |
16 |
_.shuffle(pst) It returns the shuffled copy of the pst. |
17 |
_.toArray(pst) It defines an array of the pst. |
18 |
_.size(pst) It defines the number of values in the pst. |
19 |
_.first(array, [n]) It specifies the first element of the array in the pst. |
20 |
_.initial(array, [n]) It returns everything, but specifies the last entry of the array in the pst. |
21 |
_.last(array, [n]) It specifies the last element of the array in the pst. |
22 |
_.rest(array, [index]) It defines the remaining elements in the array. |
23 |
_.without(array, *values) It returns the values of all instances which are removed in the pst. |
24 |
_.indexOf(array, value, [isSorted]) It returns the value if it is found at a specified index or returns -1, if it is not found. |
25 |
_.indexOf(array, value, [fromIndex]) It returns the last occurrence of the value in the array or returns -1, if it is not found. |
26 |
_.isEmpty(object) It returns true if there are no values in the pst. |
27 |
_.chain(obj) It returns a wrapped object. |