Pregunta

I need to fetch a collection, then (based on parameters I set) breakdown the url/request params into smaller requests. One parameter provides the number of requests and the other sets if it should be simultaneous or consecutive.

I could make multiple fetch() requests, changing the url via a loop, but it seems like overwriting the fetch method in the collection would be the ideal approach.

Unfortunately, when I do so, parse() never gets called and the collection has no add or reset method available to it.

What is the best way to breakdown a collection into smaller requests like this?

I've tried following some related stackoverflow threads, but none of the solutions I've found have been successful.

Thanks!

¿Fue útil?

Solución

I also think that overwriting the fetch method in the collection is the ideal approach, and here's what you can do to avoid the problems you have faced:

1- Overwrite the fetch method in the collection and do your logic (number of requests and simultaneous/consecutive)

2- When you want to call the server use this method:

// this refer to the current collection
Backbone.Collection.prototype.fetch.call(this, options);

3- Pass your url in the fetch options:

...prototype.fetch.call(this, { url: /* your url*/, ...});
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top