forked from Polymer/polymer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdom-bind.html
80 lines (68 loc) · 2.05 KB
/
dom-bind.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<!doctype html>
<html>
<head>
<title>dom-bind</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="../../../webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="../../polymer.html">
</head>
<body>
<template is="dom-bind" id="app">
<h3>Repeat index</h3>
<template is="dom-repeat" items="{{employees}}">
<div style="padding: 3px 0px;">
<button on-tap="modify">Modify</button>
<span>{{index}}</span>
<span>{{item.first}}</span>
<span>{{item.last}}</span>
</div>
</template>
<h3>Show person by index, demonstrate "dom-if" expressions</h3>
<template is="dom-repeat" items="{{employees}}">
<div>
<template is="dom-if" if="{{testit(index)}}">
<div style="padding: 3px 0px;">
<button on-tap="modify">Modify</button>
<span>{{index}}</span>
<span>{{item.first}}</span>
<span>{{item.last}}</span>
</div>
</template>
</div>
</template>
<h3>Show person by index, demonstrate filter</h3>
<template is="dom-repeat" items="{{employees}}" filter="onlyRob">
<div>
<div style="padding: 3px 0px;">
<button on-tap="modify">Modify</button>
<span>{{index}}</span>
<span>{{item.first}}</span>
<span>{{item.last}}</span>
</div>
</div>
</template>
</template>
<script>
var logEl = document.getElementById('log');
var app = document.getElementById('app');
app.testit = function(i) {
return i > 1;
};
app.modify = function(e) {
e.model.set('item.last', e.model.item.last + '*');
};
app.onlyRob = function(item) {
return item.first == 'Rob';
};
app.bar = true;
app.employees = [
{first: 'Bob', last: 'Smith'},
{first: 'Sally', last: 'Johnson'},
{first: 'Rob', last: 'Instructs'},
{first: 'Scott', last: 'Explains'},
{first: 'Taylor', last: 'Blogs'}
];
</script>
</body>
</html>