forked from canjs/canjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathejs.html
55 lines (49 loc) · 1.45 KB
/
ejs.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
<html>
<head>
</head>
<body>
<div id="dummy"></div>
<!-- PUT ANY TEMPLATES YOU NEED HERE -->
<script id="listEJS" type="text/ejs">
<form>
<h1>Done items</h1>
<input type="button" value="Add item" class="add-item" />
<% items.each(function(item){%>
<% if(item.attr('is_done') === false){ %>
<div <%= (el)-> el.data('item', item) %> class="item"><%= item.title %></div>
<% } %>
<%})%>
</form>
</script>
<script type='text/javascript' src='../../lib/steal/steal.js'></script>
<script type='text/javascript'>
steal(function() {
steal.config({
root: '../../'
});
}).then('can/view/ejs', 'can/control','can/model',function(){
Dummy = can.Control({
init: function(element, options) {
can.append(this.element, can.view('listEJS', {
items: this.options.list
}));
},
"div click" : function(el, ev){
el.data('item').attr('is_done', true);
},
".add-item click" : function(el, ev){
var item = new Item({title: "Title " + (this.options.list.length + 1), is_done: false})
this.options.list.push(item)
}
});
can.Model('Item', {}, {});
var list = new Item.List;
for(var i = 0; i < 2; i++){
var item = new Item({title: "Title " + i, is_done: (i % 2 === 0)})
list.push(item)
}
new Dummy('#dummy', {list: list});
})
</script>
</body>
</html>