How to access a models data from a view in Backbone.js?

devquora
devquora

Posted On: Feb 22, 2018

 

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'))
    }
});

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    Backbone js Interview Questions

    Explain what is Backbonejs?

    Backbone.js is a client-side (Model, View, Controller) MVC-based JavaScript framework.It purely is written in Javascrip..

    Backbone js Interview Questions

    List Dependencies of using BackboneJs?

    Backbone’s Js only hard dependency is Underscore.js ( >= 1.8.3). For RESTful persistence and DOM manipulation with..

    Backbone js Interview Questions

    What is the use of BackboneJS route?

    The Backbone.js router is used to change the URL fragment or hashes of an application to create bookmarkable and shareab..