Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: recipes/web/html/manipulating_queryAll_results.html

Issue 14109034: Recipes for using CSS Selectors with dart:html (Closed) Base URL: https://github.com/dart-lang/cookbook.git@master
Patch Set: Incorporated changes recommended by Seth Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2
3 <html>
4 <body>
5 <ol>
6 <li>Google</li>
7 <li>StackOverflow</li>
8 <li>Reddit</li>
9 <li>Github</li>
10 </ol>
11
12 <script type="application/dart">
13 import 'dart:html';
14
15 void doSomethingWith(element) {}
16
17 void main() {
18 List<Element> elements = queryAll('li');
19
20 // Index.
21 assert(elements[2].text == 'Reddit');
22 assert(elements.last.text == 'Github');
23 assert(elements.first.text == 'Google');
24
25 // Iterate.
26 for (var element in elements) {
27 doSomethingWith(element);
28 }
29
30 Iterable sites = elements.map((site) => site.text);
31 assert(sites.join(', ') == "Google, StackOverflow, Reddit, Github");
32
33 sites = elements.where((site) => site.text.length != 6);
34 assert(sites.first.text == "StackOverflow");
35
36 // Sublist.
37 var sublist = elements.sublist(1, 3);
38 assert(sublist.first.text == 'StackOverflow');
39 assert(sublist.last.text == 'Reddit');
40
41 // Call predicates.
42 assert(elements.any((element) => element.text.length == 6));
43 assert(elements.every((element) => element.text.length == 6) == false);
44
45 // Search.
46 assert(elements.lastWhere((element) => element.text.length == 6).text == 'Github');
47
48 // The list of results is readonly.
49 try {
50 elements.length = 2;
51 } catch(e) {
52 assert(e.message == 'Cannot resize immutable List.');
53 }
54 }
55
56 </script>
57 <script src="packages/browser/dart.js"></script>
58 </body>
59 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698