Hey all. So I am trying to integrate a data collection library with
backbone. My assumption would be to override the 'fetch' function and use
it to initiate my data collection library as needed.
My data collection library polls data from remote JSON-P APIs and then
passes each collected item to my supplied callback. I have a HyveItem model
prepared to handle the output so I would assume I just need to call create,
however for some reason even with an explicit bind, 'this' in this.create
appears to be the Window object, which obviously breaks things.
Any advice?
var HyveItems = Backbone.Collection.extend(
{ model: HyveItem
, localStorage: new Backbone.LocalStorage("HyveItems")
, max_items: 100
, initialize: function(opts){
this.on('add', this.trim)
}
, trim: function(){ if(this.length > this.max_items) this.shift() }
, fetch: function(options){
this.reset()
var callback = _.bind(this.create, this)
// hyve collects data from many different json-p feeds.
// create is used as a callback here for each returned item
hyve.friends.stream( callback, options )
}
, pause: function() {
hyve.stop()
}
}
);