I am trying to fill instagram images using the trunk,
I basically have 3 models,
User model stores all user information related to instagram
App.Models.User = Backbone.Model.extend({ defaults: { id: '', access_token: '', userid: '', username: '', full_name: '', profile_picture: '' }, urlRoot: "/api/user/", initurl: function() { return "https://api.instagram.com/v1/users/"+this.get('userid')+"/media/recent/?access_token=" + this.get('access_token'); }, initialize: function() { this.set('id', $('#domdump .id').val()); this.fetch({ success: function(model) { var photos = new App.Collections.Ig_photos([],{ url: model.initurl() }); } }); } });
Model for storing the following pagination URL
App.Models.Ig_next_url = Backbone.Model.extend({ defaults: { next_url: '' }, next_url:function(){ return this.get('next_url'); } });
Model for photo
App.Models.Ig_photo = Backbone.Model.extend({});
Collection for several photos
App.Collections.Ig_photos = Backbone.Collection.extend({ model: App.Models.Ig_photo, initialize: function(model, options) { this.url = options.url; this.nextSet(); }, sync: sync_jsonp, parse: function( response ) { if(response.pagination && response.pagination.next_url && response.pagination.next_url != this.url){ var next_url = new App.Models.Ig_next_url({ next_url: response.pagination.next_url }); this.url = next_url.next_url(); } return response.data; }, nextSet: function(){ this.fetch({ success: function(photos){ var ig_photos_views = new App.Views.Ig_photos_view({ collection: photos}); console.log(photos); } }); } });
Also, I have some views that render the button with a larger download, which calls the next collection set.
What I tried to achieve was adding photos to the collection on nextset (), and the collection is updated with data with new data and new data, but now they are being rewritten.
Can I also create a new collection from modelfetch?