Search
 
SCRIPT & CODE EXAMPLE
 

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

Backbone Template

-the content of your template view is what is inside the <script id> </script> 
- this.$el.html(this.template(this.model.toJSON()) this line is what is setting the value of each individual view/template's html. Without it.
-For example. If you instead wrote this.$el.html("hello world") , each element would just be "hello world".
- <input class="edit" value="<%- title %>"> is the this.input=    this.input = this.$('.edit');
Comment

Backbone Template()

While commonly used, template is NOT A default function/property of view, it is added in afterwards….during Backbone.View.extend({/*here*/}} you can add ANY property…{clown: , pies: } are all okay…
Comment

Backbone Template

Inside of template you add the value of the variables you want to use inside of the template
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript enter key 
Javascript :: JSON of first block in cryptocurrency blockchain 
Javascript :: express get, post, delete, put template 
Javascript :: Backbone Model Setting, Has And Getting 
Javascript :: backbone view 
Javascript :: backbone view initialize 
Javascript :: toISOString() in electron 
Javascript :: base64-XMLHttpRequest 
Javascript :: clear an array 
Javascript :: for-loop-how-to-loop-through-an-array-in-js 
Javascript :: xor two hex strings js 
Javascript :: jquery try catch 
Javascript :: copy array 
Javascript :: cookies javascript 
Javascript :: or js 
Javascript :: dynamic styles in react native 
Javascript :: class in js 
Javascript :: jquery search string for substring 
Javascript :: for-in loop 
Javascript :: javascript post request 
Javascript :: Run FEnvQueryRequest 
Javascript :: inappbrowser hide url 
Javascript :: eleventy filter newlines 
Javascript :: javascript Passing Parameter as Default Values 
Javascript :: javascript Octal syntax is not allowed 
Javascript :: find the missing number javascript 
Javascript :: how to convert a title to a url slug in jquery 
Javascript :: get page scrolling amount js 
Javascript :: phaser rotate container facing point 
Javascript :: closre in js 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =