In my Backbone function, i am fetching the data from server as first time.(it has bunch of datas) and i am adding to document. According to the client requirement i should keep watch the server every 10sec, and need to apply the elements to the document. I am always using the “reset” call back to render the elements..
But i need to apply all the element to document as firt time, later part just it is enough to update, how can i do like..?
here is a partial stuff from my code:
initialize:function(params){
_.bindAll(this);
var that = this;
this.listItems = ["projectName","assignedTo","projectName"];
this.classItems = ["projectName","assignedTo","sortBy"];
this.listCatch = [];this.boardCatch=[];
this.params = params;
for(var i=0;i<this.listItems.length; i+=1){
this.listCatch[i] = [];
}
this.collection = new singleton.collection;
this.collection.on('reset', this.render);
//on load resetting..
var dataFetcher = function(){
that.collection.fetch();
appDataFetcher = setTimeout(dataFetcher,10000);
// as well all times resetting the whole data...
};
var appDataFetcher = setTimeout(dataFetcher,0);
},
render:function(){
this.listCollection = this.collection;
this.boardCollection = this.collection;
this.listCollect();
this.boardViewSet();
},
listCollect:function(){
var that = this;
_(this.listItems).forEach(function(key,i){
var uniqur = _.uniq(that.listCollection.models, function(item){
return item.get(key);
});
that.listViewSet(key,i,uniqur);
});
},
I set my fetching process like this.. it works fine as like i expected. But if this is not correct approach let any one correct me..?