javascript - Saving model to new Collection then destroying it using Backbone -
wondering if can tell me if approach correct. have 2 collections - movies , watchlist both use movie model. can save movie watchlist when model watchlist: true. i'm not sure i'm doing right , love feedback.
js
onwatchlistadd: function(model) { model.togglewatchlist(); this.datastore.watchlist.add(model); model.save(null, { success: function(model, response, options) { console.log('success::', model, response, options); }, error: function(model, response, options) { console.log('error::', model, response, options); } }); }, onwatchlistremove: function(model) { model.togglewatchlist(); this.datastore.watchlist.remove(model); var clonedfilm = model.clone(); clonedfilm.destroy(null, { success: function(model, response, options) { console.log('success::', model, response, options); }, error: function(model, response, options) { console.log('error::', model, response, options); } }); }
so logic is, on adding watchlist set models watchlist attribute true add watchlist save model. on remove set watchlist attribute false, remove watchlist collection clone , destroy not remove model. seem right?
codepen: http://codepen.io/styler/pen/obbdoe
Comments
Post a Comment