javascript - Backbone.js el error -


i'm learning backbone.js, still in beginning i'm getting error:

uncaught typeerror: cannot call method 'html' of undefined   

on line this.$el.html( template );

<body>                 <div id="search_container"></div>                 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>                 <script src="http://ajax.cdnjs.com/ajax/libs/json2/20110223/json2.js"></script>                 <script src="http://ajax.cdnjs.com/ajax/libs/underscore.js/1.1.6/underscore-min.js"></script>                 <script src="http://ajax.cdnjs.com/ajax/libs/backbone.js/0.3.3/backbone-min.js"></script>                 <script type="text/template" id="search_template">                         <label>search</label>                         <input type="text" id="search_input" />                         <input type="button" id="search_button" value="search" />                 </script>                 <script type="text/javascript">                         $(document).ready(function()                         {                                  searchview = backbone.view.extend({                                 initialize: function(){                                         this.render();                                 },                                 render: function(){                                         // compile template using underscore                                         var template = _.template( $("#search_template").html(), {});                                         // load compiled html backbone "el"                                         this.$el.html( template );                                 }                                 });                                  var search_view = new searchview({ el: $("#search_container") });                         });                 </script>         </body> 

why error occuring?

you setting el element of view

new searchview({ el: $("#search_container") }); 

but in html element present. cause error, defining el way means have element present on page , assigning element container view.

either add element html or edit below

new searchview(); 

so el fall div default.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -