I've been trying my hand at Backbone recently and have a very basic question.
I need to search for different kind of records and the search API returns a JSON response like
{ foo:
[
{ name: 'foo1', url: '/foo1' },
{ name: 'foo2', url: '/foo2' }
],
bar:
[ { name: 'bar1', url: '/bar1' } ],
baz:
[ { name: 'baz1', url: '/baz1' } ]
}
I have a backbone model for Foo, Bar and Baz. A collection which on fetch should hit my server and get me the search results. I attempted something like
window.searchEntities = Backbone.Collection.extend({
url: '/get_search_results'
model: function(attrs, options) {
//Typecast the JSON to Foo, Bar and Baz Models
});
});
However, I do not know how to parse the results returned by server so that my collection holds models Foo, Bar and Baz? Or should I tweak the results returned by server so that its easier to handle this with Backbone?
functionis not returning any thing.. and I don't think any one is gonna sendattrsandoptionsto yourCollection.model()... and even if you receive your JSON request as theattrsparam thisattrs['foo']is not matching with any thing in your JSON example. Summarizing: I think you should rebuild your question to try to avoid confuse information. - fguillen