forked from joaool/MotherGithub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackbone2.html
58 lines (56 loc) · 2.13 KB
/
backbone2.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
55
56
57
58
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Backbone v2.0</title>
</head>
<body>
<div id="container">
<button>Load</button>
<ul id="list">
</ul>
</div>
<div id="list-template">
<li><a href=""></a></li>
</div>
<!--<script type="text/javascript" charset="utf-8" src="../rivets/dist/rivets.js" ></script>-->
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<!--<script type="text/javascript" charset="utf-8" src="../q-1/q.js" ></script>
<script type="text/javascript" src="http://documentcloud.github.com/underscore/underscore-min.js"></script>
<script type="text/javascript" src="http://documentcloud.github.com/backbone/backbone-min.js"></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>
<script type="text/javascript">
model = new Backbone.Model({
data:[
{text:"Google",href:"http://google.com"},
{text:"Facebook",href:"http://facebook.com"},
{text:"YouTube",href:"http://youtube.com"}
]
});
var View = Backbone.View.extend({
initialize:function(){
console.log("Initializing view with..." + this.options.JOBlankOption );
this.xtemplate = $("#list-template").children(); //we want the li line.
},
el:"#container", //the prebuild option is used here meaning that this view always refers to #container
events:{
"click button":"render" //this will trigger button in container, outside the container will not receive the event...
},
render:function(){
var data = this.model.get("data");
for (var i=0; i<data.length; i++) {
console.log("line= "+i+" "+data[i].text);
var li = this.xtemplate.clone().find("a").attr("href",data[i].href).text(data[i].text).end();
this.$el.find("ul").append(li);
}
// alert("JO");
return null;
}
});
var view = new View({model:model,JOBlankOption:"empty string"});
// el is a prebuilt option
console.log(document.title+"...... END..");
</script>
</body>
</html>