1

在我的 Backbone 函数中,我第一次从服务器获取数据。(它有一堆数据)并且我正在添加到文档中。根据客户要求,我应该每 10 秒监视一次服务器,并且需要将元素应用于文档。我总是使用“重置”回调来渲染元素..

但是我需要将所有元素应用到文档作为第一次,稍后部分就足够了更新,我该怎么做..?

这是我的代码中的部分内容:

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);
            });
        },
4

1 回答 1

0

我像这样设置我的获取过程..它像我预期的那样工作得很好。但是,如果这不是正确的方法,让任何人纠正我..?

this.collection.on('add', this.render); 
this.collection.on('remove', this.render);  
        var dataFetcher = function(){
            that.collection.fetch({update:true,remove:true});
            appDataFetcher = setTimeout(dataFetcher,10000);
        };
 var appDataFetcher = setTimeout(dataFetcher,0);    
于 2013-02-14T13:05:01.317 回答