|
| 1 | +<!doctype html> |
| 2 | +<html> |
| 3 | +<head> |
| 4 | + |
| 5 | + <title>dom-bind</title> |
| 6 | + |
| 7 | + <meta charset="utf-8"> |
| 8 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 9 | + |
| 10 | + <script src="../../../webcomponentsjs/webcomponents-lite.js"></script> |
| 11 | + <link rel="import" href="../../polymer.html"> |
| 12 | + |
| 13 | +</head> |
| 14 | +<body> |
| 15 | + |
| 16 | + <template is="dom-bind" id="app"> |
| 17 | + |
| 18 | + <h3>Repeat index</h3> |
| 19 | + <template is="dom-repeat" items="{{employees}}"> |
| 20 | + <div style="padding: 3px 0px;"> |
| 21 | + <button on-tap="modify">Modify</button> |
| 22 | + <span>{{index}}</span> |
| 23 | + <span>{{item.first}}</span> |
| 24 | + <span>{{item.last}}</span> |
| 25 | + </div> |
| 26 | + </template> |
| 27 | + |
| 28 | + <h3>Show person by index, demonstrate "dom-if" expressions</h3> |
| 29 | + <template is="dom-repeat" items="{{employees}}"> |
| 30 | + <div> |
| 31 | + <template is="dom-if" if="{{testit(index)}}"> |
| 32 | + <div style="padding: 3px 0px;"> |
| 33 | + <button on-tap="modify">Modify</button> |
| 34 | + <span>{{index}}</span> |
| 35 | + <span>{{item.first}}</span> |
| 36 | + <span>{{item.last}}</span> |
| 37 | + </div> |
| 38 | + </template> |
| 39 | + </div> |
| 40 | + </template> |
| 41 | + |
| 42 | + </template> |
| 43 | + |
| 44 | + <script> |
| 45 | + var logEl = document.getElementById('log'); |
| 46 | + var app = document.getElementById('app'); |
| 47 | + app.testit = function(i) { |
| 48 | + return i > 1; |
| 49 | + }; |
| 50 | + app.modify = function(e) { |
| 51 | + e.model.set('item.last', e.model.item.last + '*'); |
| 52 | + }; |
| 53 | + app.bar = true; |
| 54 | + app.employees = [ |
| 55 | + {first: 'Bob', last: 'Smith'}, |
| 56 | + {first: 'Sally', last: 'Johnson'}, |
| 57 | + {first: 'Rob', last: 'Instructs'}, |
| 58 | + {first: 'Scott', last: 'Explains'}, |
| 59 | + {first: 'Taylor', last: 'Blogs'} |
| 60 | + ]; |
| 61 | + |
| 62 | + </script> |
| 63 | + |
| 64 | +</body> |
| 65 | +</html> |
0 commit comments