2016-03-21 17 views
0
下面

是喜是我写的代码,它是从互联网教程例子(https://cdnjs.com/libraries/backbone.js/tutorials/what-is-a-view/Backbone.js的错误“Backbone.View.Extend是不是一个函数”

<<!DOCTYPE html> 
<html> 
<head> 
    <script src="https://code.jquery.com/jquery-2.1.3.min.js" type="text/javascript"></script> 
    <script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.3.3/underscore-min.js" type="text/javascript"></script> 
    <script src="http://cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.2/backbone-min.js" type="text/javascript"></script> 
</head> 

<body> 
    <div id ="search_container">a</div> 
    <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"> 
     SearchView = Backbone.View.Extend({ 
      initialize: function(){ 
       this.render(); 
      }, 
      render: function(){ 
       // Compile the template using underscore 
       var template = _.template($('search_template').html(),{}); 
       // Load the compiled HTML into the Backbone "el" 
       this.$el.html(template); 
      }, 
      events:{ 
       "click input[type=button]": "doSearch" 
      }, 
      doSearch: function(){ 
       alert("search for " + $('#search_input').val()); 
      } 
     }); 

     var search_view = new SearchView({el: $('#search_container')}); 
    </script> 

</body> 
</html> 

我不明白我我做错了,请指导我。感谢

+3

Backbone.View.extend:以小写ê – nikoshr

+0

延长您可能想要使用更新版本的Backbone和Underscore。你应该改变'_.template(tmpl,data)'为't = _.template(tmpl); h = t(data)'因为['_.template'接口在1.7.0中更改](http://stackoverflow.com/a/25881231/479863)。 –

回答

1

nikoshr是正确的,你必须使用小写和形式使工作扩展的例子,你必须改变

var template = _.template($('search_template').html(),{}); 

var template = _.template($('#search_template').html(),{}); 
相关问题