backbone.js - Backbone collection empty issue -
fetch: function() { var self = this; self.each(function(track) { if(track) { track.destroy(); } }); backbone.sync('fetch', this, { method: 'get', success: function(response) { if (response) { if(response.clips.length > 0) { spinneron(); (i = 0; < response.clips.length; i++) { self.loadcount++; self.loadfile(response.clips[i]); } } } } }); }
on fetch above trying empty collection not emptying first record in collection ,the above sync operation loading saved datas database.
from @try-catch-finally users comment writing , 100% work out.
fetch: function() { var self = this; while(self.length) { self.at(0).destroy() } backbone.sync('fetch', this, { method: 'get', success: function(response) { if (response) { if(response.clips.length > 0) { spinneron(); (i = 0; < response.clips.length; i++) { self.loadcount++; self.loadfile(response.clips[i]); } } } } }); }
while(self.length) { self.at(0).destroy() } destroy models in collection
Comments
Post a Comment