Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
20
rated 0 times [  23] [ 3]  / answers: 1 / hits: 33155  / 13 Years ago, thu, march 31, 2011, 12:00:00

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.


More From » jquery

 Answers
9

instead of



[id1, id2, ..., idn]


the client expects



[{id: id1}, ... {id: idn}]

[#92987] Wednesday, March 30, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
shianncaylinc

Total Points: 502
Total Questions: 80
Total Answers: 105

Location: Botswana
Member since Sat, Jan 7, 2023
1 Year ago
;