Backbone.js - 添加参数发送到fetch不会触发集合

时间:2013-01-22 14:07:08

标签: backbone.js

  

可能重复:
  Backbone.js - change not triggering while the name change
  Backbone - how get this sort out… some part still not clear

在我的骨干函数中,我在使用setTimout继续获取数据时,我获取数据,我发送属性为{add:true}所以这意味着,我新获得的模型将会添加现有集合,当集合添加模型时,它应该触发add方法。

但我没有在我的收藏中制作后添加过程的触发器。但我在查看过程中获取数据,这是不正确的。

我的收藏:

list.collect = Backbone.Collection.extend({
  model:list.model,
  url : 'data/names.json',
  initialize:function(){
     this.fetch({success:this.prompter});
     this.on("add", this.addOne, this);//it should get triggered while added the model
  },
  addOne:function(e){
    console.log('addone'); // the method not called
  }
});

我的观点:

list.view = Backbone.View.extend({
  initialize:function(){
    this.collection = new list.collect();

    var that = this;
    var updateData = function(){
      that.collection.fetch({add:true}); // i am passing add:true!
      myTimeout = setTimeout(updateData,10000)
    }
    var myTimeout = setTimeout(updateData,10000)

    this.collection.on("reset", this.render, this);

  },
  render:function(data){
    _.each(this.collection.models, function(data){
      //console.log(data.get('name'));
    })
  }
});

请问这个问题吗?

0 个答案:

没有答案