D
D
deadkEEper12015-10-18 16:09:25
HTML
deadkEEper1, 2015-10-18 16:09:25

How to render Backbone-View so that a new element is created, not text?

var Person = Backbone.Model.extend({})

var PersonView = Backbone.View.extend({
    el:'body',
  template: _.template($('#userTemplate').html() ),
  initialize: function(){
    this.render();
    console.log(this)

  },

  render:function(){
    console.log(this.model.toJSON() )
    this.$el.append( this.template(this.model.toJSON() )) 
    return this
  }
})

function save(){
  var name = $('#name').val()
  var newPerson = new Person({name: name})

  var personView = new PersonView({model: newPerson});
    personView.el

}

The page has one button and one input. The button reacts to the click by running the save() function. It, in turn, takes the value from the input, creates a new backbone model, runs it through the template and renders it in the body html'a . But it sends the text, how to fix it in order to get the html element at the output? If possible with an example, thanks!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question