Online interview questions

Prepare interviews on Anything, AnyWhere

In order to access a models data from a view in backbone.js you have to initialize your Model :


var author= Backbone.Model.extend({
      initialize: function(){
        console.log('intailized');
      },
      defaults:{
          names:['Bob','Sim','Dart']
      }
    })
var person_view = Backbone.View.extend({
    initialize: function() {
        this.model = new author();
    },
    output: function(){
        console.log(this.model.get('names'))
    }
});