我試圖在我的頁面上呈現搜索框。我試圖保持在一個單獨的觀點。沒有這個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