Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backbone.js: How to get the index of a model in a Backbone Collection?

Tags:

backbone.js

People also ask

How do you find model index?

To obtain a model index that refers to an existing item in a model, call QAbstractItemModel::index() with the required row and column values, and the model index of the parent.

How can we get the attribute value of a model in Backbone JS?

js Get model is used to get the value of an attribute on a model. Syntax: model. get(attribute)

What is collections in Backbone JS?

Advertisements. 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.


yes, backbone provides access to many underscore.js methods on models and collections, including an indexOf method on collections. it also provides an at method like you've shown.

var index = this.collection.indexOf(this.model);
var modelAbove = this.collection.at(index-1);