Skip to content

Instantly share code, notes, and snippets.

@boxxxie
Created October 28, 2011 20:40
Show Gist options
  • Save boxxxie/1323487 to your computer and use it in GitHub Desktop.
Save boxxxie/1323487 to your computer and use it in GitHub Desktop.
/*
>>> campaignList.at(0).fetch()
GET http://localhost:5984/campaigns/_all_docs/AllCanadaAllTerminal
I want this to happen
GET http://localhost:5984/campaigns/AllCanadaAllTerminal
*/
var Campaign = Backbone.Model.extend(
{
idAttribute: "_id",
url:"http://localhost:5984/campaigns/" + this._id
});
var Campaigns = Backbone.Collection.extend(
{
model: Campaign,
url:"http://localhost:5984/campaigns/_all_docs",
parse: function(response) {
return _(response.rows).chain()
.pluck('id')
.reject(function(id){return id.search('_design') == 0;})
.map(function(id){return new Campaign({_id:id});})
.value();
}
});
campaignList = new Campaigns();
campaignList.fetch(
{ include_docs:true,
success:function(model,resp){
console.log("model");
console.log(model);
console.log("resp");
console.log(resp);
_.each(model,function(model)
{
model.fetch({success:console.log});
});
}});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment