OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | |
2 // for details. All rights reserved. Use of this source code is governed by a | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 library jsonp_sample; | |
6 | |
7 import 'dart:html'; | |
8 import 'dart:js'; | |
9 | |
10 const List<String> FIELDS = const ['name', 'description', 'size', | |
11 'watchers', 'forks']; | |
12 | |
13 TableElement table = querySelector('#repo-table'); | |
14 | |
15 addTableHeadRow() { | |
16 var tr = new TableRowElement(); | |
17 for (var field in FIELDS) { | |
18 tr.append(new Element.tag('th')..text = field); | |
19 } | |
20 table.querySelector('thead').append(tr); | |
21 } | |
22 | |
23 addTableBodyRow(JsObject repo) { | |
24 var tr = new TableRowElement(); | |
25 for (var field in FIELDS) { | |
26 var td = new TableCellElement(); | |
27 if (field == 'name') { | |
28 td.append(new AnchorElement() | |
29 ..href = repo['html_url'] | |
30 ..text = repo[field]); | |
31 } else { | |
32 td.text = repo[field].toString(); | |
33 } | |
34 tr.append(td); | |
35 } | |
36 table.querySelector('tbody').append(tr); | |
37 } | |
38 | |
39 void main() { | |
40 // Create a jsObject to handle the response. | |
41 context['processData'] = (response) { | |
42 addTableHeadRow(); | |
43 for (var repo in response['data']) { | |
44 addTableBodyRow(repo); | |
45 } | |
46 }; | |
47 | |
48 ScriptElement script = new Element.tag("script"); | |
49 script.src = "https://api.github.com/users/dart-lang/repos?callback=processDat
a"; | |
50 document.body.children.add(script); | |
51 } | |
OLD | NEW |