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 :: use function in mongodb query example 
Javascript :: problem with Next.js and @material-ui. 
Javascript :: pnpm tailwind react 
Javascript :: vue append component to div 
Javascript :: Backbone Render 
Javascript :: Deployment of react static page using node and express 
Javascript :: javascript variable scope in if statement 
Javascript :: swal on submit angular with cancel butotn 
Javascript :: name of javascript virtual machine for apple 
Javascript :: Backbone Sync And Fetch 
Javascript :: react private routes 
Javascript :: javascript count number of lines of a text 
Javascript :: java script return array 
Javascript :: how to decrypt md5 hash 
Javascript :: inline css in react js 
Javascript :: redirect in react-router-dom v6 
Javascript :: table to excel javascript 
Javascript :: javascript find vs filter 
Javascript :: multiple path names for a same component in react router v6 
Javascript :: moment js remove seconds 
Javascript :: javascript post request 
Javascript :: javascript prefill form 
Javascript :: optional css tippy 
Javascript :: selectize in ajax call 
Javascript :: matrix calculator in js 
Javascript :: random number 1-3 
Javascript :: get max type value in solidity 
Javascript :: timertask jquery 
Javascript :: change rotation phaser 
Javascript :: phaser create animation without frame names 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =