-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo5.html
54 lines (47 loc) · 1.62 KB
/
demo5.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<!DOCTYPE html>
<html>
<meta charset="GB18030">
<head>
<title>View</title>
</head>
<body>
<div id="search_container"></div>
<script type="text/template" id="search_template">
<label><%= search_label %></label>
<input type="text" id="search_input" />
<input type="button" id="search_button" value="Search" />
</script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://documentcloud.github.com/underscore/underscore-min.js"></script>
<script src="http://documentcloud.github.com/backbone/backbone-min.js"></script>
<script src="http://igame.qq.com/v2.0/js/lib/template.min.js"></script>
<script>
(function ($) {
SearchView = Backbone.View.extend({
initialize: function(){
},
render: function(context) {
/*
//使用underscore这个库,来编译模板
var template = _.template($("#search_template").html(), context);
//加载模板到对应的el属性中
$(this.el).html(template);
*/
//使用art这个库,来编译模板
var viewHtml_ = template.render('search_template',context);
//加载模板到对应的el属性中
$(this.el).html(viewHtml_);
},
events:{ //就是在这里绑定的
'click input[type=button]' : 'doSearch' //定义类型为button的input标签的点击事件,触发函数doSearch
},
doSearch: function(event){
alert("search for " + $("#search_input").val());
}
});
var searchView = new SearchView({el: $("#search_container")});
searchView.render({search_label: "搜索渲染"}); //这个reander的方法可以放到view的构造函数中,这样初始化时就会自动渲染
})(jQuery);
</script>
</body>
</html>