0

I am consoling the height, while it get changed, as well i am binding the change event to the element. still i am not getting the console output here...

i am very new to backbone, any one correct my mistake?

var Person = Backbone.Model.extend({
                initialize:function(){
                    var getHeight = prompt('provide your height');
                    this.set({height:getHeight}); //i am changing the height...
                    this.bind('change:height',function(){
                        console.log(this.get('height'));  //i am not getting any console here...  
                    })
                },
                defaults:{
                    name:'new Name',
                    height:'unknown'
                }

            });

            var person = new Person();
3gwebtrain
  • 14,640
  • 25
  • 121
  • 247

1 Answers1

1

Set the value after the binding if you want to monitor the event:

var Person = Backbone.Model.extend({
    initialize:function(){
        // bind is deprecated
        this.on('change:height',function(){
            console.log(this.get('height'));
        });

        var getHeight = prompt('provide your height');
        this.set({height:getHeight});
    },
    defaults:{
        name:'new Name',
        height:'unknown'
    }
});
nikoshr
  • 32,926
  • 33
  • 91
  • 105