| OLD | NEW |
| (Empty) |
| 1 library jsonp_sample; | |
| 2 | |
| 3 import 'dart:html'; | |
| 4 | |
| 5 import 'package:js/js.dart'; | |
| 6 | |
| 7 const List<String> FIELDS = const ['name', 'description', 'size', | |
| 8 'watchers', 'forks']; | |
| 9 | |
| 10 TableElement table = querySelector('#repo-table'); | |
| 11 | |
| 12 addTableHeadRow() { | |
| 13 var tr = new TableRowElement(); | |
| 14 for (var field in FIELDS) { | |
| 15 tr.append(new Element.tag('th')..text = field); | |
| 16 } | |
| 17 table.querySelector('thead').append(tr); | |
| 18 } | |
| 19 | |
| 20 addTableBodyRow(Proxy repo) { | |
| 21 var tr = new TableRowElement(); | |
| 22 for (var field in FIELDS) { | |
| 23 var td = new TableCellElement(); | |
| 24 if (field == 'name') { | |
| 25 td.append(new AnchorElement() | |
| 26 ..href = repo.html_url | |
| 27 ..text = repo[field]); | |
| 28 } else { | |
| 29 td.text = repo[field].toString(); | |
| 30 } | |
| 31 tr.append(td); | |
| 32 } | |
| 33 table.querySelector('tbody').append(tr); | |
| 34 } | |
| 35 | |
| 36 void main() { | |
| 37 // Create a jsObject to handle the response. | |
| 38 context.processData = (response) { | |
| 39 addTableHeadRow(); | |
| 40 for (var i = 0; i < response.data.length; i++) { | |
| 41 addTableBodyRow(response.data[i]); | |
| 42 } | |
| 43 }; | |
| 44 | |
| 45 ScriptElement script = new Element.tag("script"); | |
| 46 script.src = "https://api.github.com/users/dart-lang/repos?callback=processDat
a"; | |
| 47 document.body.children.add(script); | |
| 48 } | |
| OLD | NEW |