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

Unified 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: Changes based on Kathy's comments. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « recipes/web/html/inserting_elements_outside.html ('k') | recipes/web/html/removing.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: recipes/web/html/manipulating_queryAll_results.html
diff --git a/recipes/web/html/manipulating_queryAll_results.html b/recipes/web/html/manipulating_queryAll_results.html
new file mode 100644
index 0000000000000000000000000000000000000000..5319f053cb50fad454d53b03fafd1913da338137
--- /dev/null
+++ b/recipes/web/html/manipulating_queryAll_results.html
@@ -0,0 +1,59 @@
+<!DOCTYPE html>
+
+<html>
+ <body>
+ <ol>
+ <li>Google</li>
+ <li>StackOverflow</li>
+ <li>Reddit</li>
+ <li>Github</li>
+ </ol>
+
+ <script type="application/dart">
+ import 'dart:html';
+
+ void doSomethingWith(element) {}
+
+ void main() {
+ List<Element> elements = queryAll('li');
+
+ // Index.
+ assert(elements[2].text == 'Reddit');
+ assert(elements.last.text == 'Github');
+ assert(elements.first.text == 'Google');
+
+ // Iterate.
+ for (var element in elements) {
+ doSomethingWith(element);
+ }
+
+ Iterable sites = elements.map((site) => site.text);
+ assert(sites.join(', ') == "Google, StackOverflow, Reddit, Github");
+
+ sites = elements.where((site) => site.text.length != 6);
+ assert(sites.first.text == "StackOverflow");
+
+ // Sublist.
+ var sublist = elements.sublist(1, 3);
+ assert(sublist.first.text == 'StackOverflow');
+ assert(sublist.last.text == 'Reddit');
+
+ // Call predicates.
+ assert(elements.any((element) => element.text.length == 6));
+ assert(elements.every((element) => element.text.length == 6) == false);
+
+ // Search.
+ assert(elements.lastWhere((element) => element.text.length == 6).text == 'Github');
+
+ // The list of results is readonly.
+ try {
+ elements.length = 2;
+ } catch(e) {
+ assert(e.message == 'Cannot resize immutable List.');
+ }
+ }
+
+ </script>
+ <script src="packages/browser/dart.js"></script>
+ </body>
+</html>
« no previous file with comments | « recipes/web/html/inserting_elements_outside.html ('k') | recipes/web/html/removing.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698