I have a situation using backbone.js where I have a collection of models and additional information about models. For example, imagine that I am returning a list of sums: they have an amount associated with each model. Suppose now that the unit for each of the sums is always the same: say, quarts. Then the json object that I will return from my service might look something like this:
{ dataPoints: [ {quantity: 5 }, {quantity: 10 }, ... ], unit : quarts }
Now basic collections do not have a real mechanism for naturally linking this metadata to the collection, but I was asked in this question: Setting attributes in the collection is js trunk , so I can expand the collection using the style function .meta(property, [value]) - This is a great solution. However, of course, we should be able to cleanly extract this data from a json response similar to the one we had above.
Backbone.js gives us a parse(response) function that allows us to specify where to retrieve a list of model collections from a combination with the url attribute. However, I do not know how to make a more intelligent function without overloading fetch() , which will remove the partial functionality that is already available.
My question is this: is there a better option than overloading fetch() (and trying to call it an implementation of a superclass) to achieve what I want to achieve?
thank
idbentley May 09 '11 at 2:25 am 2011-05-09 02:25
source share