I'm trying to fetch a collection from my server. I'm using version 0.3.3 (not the master from github) However I am running in this exception:
Uncaught TypeError: Cannot use 'in' operator to search for 'id' in {id=MyId, active=true}
jQuery.jQuery.extend._Deferred.deferred.resolveWith (jquery.js:869)
done (jquery.js:6591)
jQuery.ajaxTransport.send.callback
This is the way I created the error:
var MyModel = Backbone.Model.extend();
var MyCollection = Backbone.Collection.extend({
url: '/api/collection',
model: MyModel
});
var coll = new MyCollection();
coll.fetch();
The elements in /api/collection are parsed in JSON. I tried to return them in various formats
["Id1", "Id2", ... ]
[{id: "Id1, somethingElse: "..."}, ...]
{id1: { id1s content}, id2: { ... }, ...}
However the error was always the same. What is wrong with this code?
[Edit] It doesn't help to set an error via coll.fetch({error: errorFunc});
The Exception stays the same.
[Edit2] Well it seems everything works fine until collection.fetch()
calls collection.refresh()
with the response object. I have not overwritten any of these functions.
[Edit3] The error is in the collection.add()
method and the reason is that my elements are a list of strings... My server sent them wrong.