Friday, 11 December 2015

Exercise-6: Loading a Template

Solution

Replace Index.html existing code with following code

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
 
</head>

<body>
<script type="text/template" id="search_template">


<input type="text" id="search_input" />
<input type="button" id="search_button" value="Search"/>


</script>
<div id="search_container"></div>


<script src="lib/jquery-1.9.1.min.js"></script>
<script src="lib/underscore-min.js"></script>
<script src="lib/backbone-min.js"></script>
<script src="js/main.js"></script>

</body>

</html>


Modify the extended backbone view (as in #5) to following

           initialize: function(){
                this.display();   //Call Display Function
},

display: function(){
var template = _.template( $("#search_template").html(), {});
this.$el.html( template );

}


    // Load the compiled HTML into the Backbone "el"
    this.$el.html( template );

No comments:

Post a Comment