Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Backbone View Template


/*the view/template  refers to individual items being added to the to do list*/
/*this is the bare minimum code needed*/
/*#item-template: there can only be one*/
  <!-- Templates -->
  <script type="text/template" id="item-template">
      <label><%- title %></label>
  </script>  


    // renders individual todo items list (li)
    app.TodoView = Backbone.View.extend({
      tagName: 'li',
      template: _.template($('#item-template').html()),
      render: function(){
        this.$el.html(this.template(this.model.toJSON()));
        return this; // enable chained calls
      }
    });
    
    
    
 
PREVIOUS NEXT
Tagged: #Backbone #View #Template
ADD COMMENT
Topic
Name
5+5 =