【发布时间】:2012-01-22 13:38:16
【问题描述】:
我看到thisBackbone 中关于简单视图的小文章。但是我尝试自己以这种方式加载模板..不起作用:(
我将代码复制并粘贴到我的文件中,但什么也没发生。这是我的代码:
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script type="text/javascript" src="js/vendor/jquery-1.7.1.js"></script>
<script src="js/vendor/underscore.js"></script>
<script src="js/vendor/backbone.js"></script>
</head>
<body>
<div id="search_container"></div>
<script type="text/javascript">
;(function(){
SearchView = Backbone.View.extend({
initialize: function(){
_.bindAll(this, 'render');
},
render: function(){
var template = _.template( $("#search_template").html(), {} );
$(this.el).html(this.template);
this.el.html( template );
}
});
var search_view = new SearchView({ el: $("#search_container") });
})(jQuery);
</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>
</body>
</html>
包含的所有脚本都是最新版本.. 我的失败是什么?
感谢所有愿意帮助我的人:)
亚安
【问题讨论】:
标签: javascript backbone.js jquery-templates