-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.dart
42 lines (33 loc) · 861 Bytes
/
client.dart
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
#import ('dart:html');
#import ('dart:json');
class client {
String _endPoint;
client(this._endPoint) {}
void render(List<Map<String, String>> data) {
StringBuffer sb = new StringBuffer();
sb.add('<ul>');
for (final Map<String, String> m in data) {
sb.add('<li>${m["id"]}:${m["message"]}</li>');
}
sb.add('</ul>');
write(sb.toString());
}
void run() {
document.query('#status').innerHTML = 'dart is running';
reload();
}
void write(String message) {
document.query('#dataList').innerHTML = message;
}
void reload() {
print('reload()');
var request = new XMLHttpRequest.getTEMPNAME(
this._endPoint, (XMLHttpRequest req) {
print('req');
render(JSON.parse(req.responseText));
});
}
}
void main() {
new client('/dart/api/data.json').run();
}