T
T
trevin2016-02-04 12:53:38
JavaScript
trevin, 2016-02-04 12:53:38

Why doesn't Underscore parse the template?

There is a code:

BookApp.Views.KeyWord = Backbone.View.extend({
    tagName: 'li',
    initialize : function(){
      this.render();      
    },
    render : function(){
      console.log(this.model.toJSON());
      this.$el.html(_.template("( -<%= name %>- )",this.model.toJSON()) ); 
      console.log(this.el);
      return this;
    }
  })

Next, this model is called, and as a result, here is the console.log:
53f17f5d41034554a6c29d7611dd3291.JPG
Please tell me why "name" was not picked up?
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
trevin, 2016-02-04
@trevin

Answer:
Because the _.template() method returns a function that takes parameters to be inserted into the compiled template by the _.template() method. Those.

var template = _.template("(<%= id %>) <%= name %>");
console.log(template({id:2, name:'Желток'}));
//  (2) Желток

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question