Reputation: 6976
I am retrieving a model from a backbone collection.
var organisation = this.collection.where({ group_id : String(elm.data('groupid')) });
this returns a result as I would expect it too.
I then when to do some getting and setting on that model, but if I try and run,
organisation.get('members')
then I get the following error message,
Uncaught TypeError: undefined is not a function
I am assuming (maybe wrongly) that is because where() does not acutally return model?
If that is the case then how can I cast the returned data into a model?
Upvotes: 1
Views: 4191
Reputation: 239240
From the docs:
where
collection.where(attributes)
Return an array of all the models in a collection that match the passed attributes. Useful for simple cases of filter
You're getting an array of records back. If you want to work with one of the returned records, either:
organisation[0].get('members')
or
organisation = organisation[0];
organisation.get('members')
Upvotes: 2