0

Hi I have a collection response from backbonejs which is access like

this.collection.models

and returns an array of length 7 - each with a model inside it.

I am trying to search across this array and get the model which matches

_id: Xmas

But everytime I try to do it I get the error

Object [object Array] has no method 'get' 

Can anyone help!?

1
  • are you applying get method on models array? Commented Mar 13, 2013 at 4:01

2 Answers 2

1

you can try this for iterating and getting value

_(collection.models).each(function(t){ 
                //console.log("loop Model"+t)
                t.get("title")
enter your required logic here
            }, this);
Sign up to request clarification or add additional context in comments.

Comments

0

You should be working with the collection and not its inner array models, then you can use the underscore methods proxied in collection, for example:

var xmasModel;
xmasModel = this.collection.find(function(item) {
  return item.get("_id") == "Xmas"
})

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.