user816604
user816604

Reputation:

Search backbonejs collections

I have a backbone js collection with multiple models:

Model 1:
tag: 1
id : 2
name: test

Model 2:
tag: 3
id: 3
name: test3

How do I search the collection for a particular model by tag attribute? Like if I want to find the model with tag=2 ... How do I do that?

Upvotes: 1

Views: 57

Answers (1)

CD..
CD..

Reputation: 74146

Use findWhere:

Returns only the first model in the collection that matches the passed attributes.

collection.findWhere({tag: 2})

Upvotes: 1

Related Questions