我试图在我的页面上呈现搜索框。我试图保持在一个单独的观点。没有这个boxview的页面正常工作,但只要我初始化我的BoxView我得到与下划线相关的错误。视图不在Backbone.js中渲染
Uncaught TypeError: Object [object Object] has no method 'replace' underscore-min.js:29
这是我的看法
/* Views */
var BoxView = Backbone.View.extend({
el: '.head',
initialize: function() {
this.render();
},
render : function(){
var that = this;
var template = _.template($('#search-box').html());
that.$el.html(template);
}
});
var boxview = new BoxView();
模板
<script type="text/template" id="search-box">
<form class="navbar-search pull-right" id="search">
<input class="search-query" name="searchText" type="text" id="searchText" placeholder="Search books"/>
<button type="submit" class="btn">Submit</button>
</form>
</script>
编辑: 删除了错字错误
可能重复的[Underscore.js模板问题 - 无法调用方法'替换'null](http://stackoverflow.com/questions/11001419/underscore-js-template-issue-cannot-call-method-replace -of-null) – 2013-04-21 16:20:27
你在_ _template($('#search-box')之前调用'_.template(null)'某处,检查$('#search-box')中的内容。 html的())'。 – 2013-04-21 16:21:25