Take the 2-minute tour ×

while reading docs of backbone i can't understand how to add model to collection with option {at: index} and then get this model using mycollection.at('index')? When im doing myCollection.add(myModel, {at: myindex}); then myCollection.at(myindex) returns undefined;

share|improve this question
Most probably values for myindex are different in one and another place. If not, you're wrong with Collection.add method. –  kirilloid Mar 7 '12 at 11:03

1 Answer 1

up vote 2 down vote accepted

Based on what you've said, it could be that your collection just isn't that long enough and your myCollection.add(myModel, {at: myindex}) isn't able to splice it in.

Some demo code to replicate your problem:

// This is all done in the console

ships = new Backbone.Collection;
ship = new Backbone.Model;

ships.add(ship, {at:100});
myCollection.at(100);    // undefined
myCollection.at(0);      // model found

Maybe some sample code if this doesn't describe the issue?

share|improve this answer
Thanks for advice. I think that i solved issue. The problem was that i tried to set index as string , like myCollection.add(myModel, {at: 'stringIndex'}); –  Sergii Kushch Mar 29 '12 at 6:57
Heh heh. I guess that would do it! –  orangewarp Mar 29 '12 at 17:55

Your Answer


