javascript - Backbone.js breaking the each loop while switching view -
javascript - Backbone.js breaking the each loop while switching view -
i have singleton backbone view :
 testview = backbone.view.extend({            initialize : function(){             _.each(array,function(arrayelement){                //-do                });        };  })  homecoming testview()    the problem want reuse view array on 'each' loop iterating big when switch views , re-enter (reuse) view, previous each loop still running. there way can stop executing each loop while switching views?
i don't think so, because _.each synchronous operation , not have  command on via flags or whatsoever.. suggest  utilize recursive settimeout (just  create asynchronous , non blocking) offset of few milliseconds , maybe able interrupt execution..
var arr = [1,2,3];  function asynceach(elementsarray) {   var element;    if (globalflag) {     element = elementsarray.shift();      // element      settimeout(function () {       asynceach(elementsarray);     }, 10);   } }        javascript backbone.js underscore.js 
 
Comments
Post a Comment