-1

Possible Duplicate:
Backbone.js - change not triggering while the name change

I made a function to learn backbone... for that i made a 'json' locally and calling that in my fetch function. as well i keep calling the fetch function every 10sec. apart from that, in between i am updating my 'local json' by manually, after the change the fetch should get me the updated stuff but it not getting me.

As well i added a function to trigger, while the name attribute change but as well not triggering when the josn update the name

this both are confusing me as well i din't get a good tutorial to learn this... any one help me to sort out this or suggest me the correct way to achieve both?

code :

(function($){

var list = {};

list.model = Backbone.Model.extend({
  defaults:{
    name:'need the name'
  }
});

list.collect = Backbone.Collection.extend({
  model:list.model,
  url : 'data/names.json',
  initialize:function(){
    this.fetch();
    this.keepUpdate();
  },
  keepUpdate:function(){
    var that = this;
    var updateData = function(){
      that.fetch();
      myTimeout = setTimeout(updateData,10000);
    }
    var myTimeout = setTimeout(updateData,10000);
  }
});


list.view = Backbone.View.extend({
  initialize:function(){
    this.collection = new list.collect();
    this.collection.on("reset", this.render, this);
    this.collection.on('change:name',function(){ console.log('name changed')}); // not triggers while i change the name attrb..
  },
  render:function(){
    _.each(this.collection.models, function(data){
      console.log(data.get('name')); // no update getting here..
    })
  }
});

var newView = new list.view();    

})(jQuery)
Community
  • 1
  • 1
3gwebtrain
  • 14,640
  • 25
  • 121
  • 247
  • Isn't this the same question as http://stackoverflow.com/questions/14453219/backbone-js-change-not-triggering-while-the-name-change ? – jevakallio Jan 22 '13 at 07:39

0 Answers0