OLD | NEW |
1 <!-- | 1 <!-- |
2 @license | 2 @license |
3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. | 3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. |
4 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt | 4 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt |
5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt | 5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt |
6 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt | 6 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt |
7 Code distributed by Google as part of the polymer project is also | 7 Code distributed by Google as part of the polymer project is also |
8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt | 8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt |
9 --><html><head><link rel="import" href="../polymer/polymer.html"> | 9 --><html><head><link rel="import" href="../polymer/polymer.html"> |
10 <link rel="import" href="../iron-resizable-behavior/iron-resizable-behavior.html
"> | 10 <link rel="import" href="../iron-resizable-behavior/iron-resizable-behavior.html
"> |
11 | 11 |
12 <!-- | 12 <!-- |
13 | 13 |
14 `iron-list` displays a virtual, 'infinite' list. The template inside | 14 `iron-list` displays a virtual, 'infinite' list. The template inside |
15 the iron-list element represents the DOM to create for each list item. | 15 the iron-list element represents the DOM to create for each list item. |
16 The `items` property specifies an array of list item data. | 16 The `items` property specifies an array of list item data. |
17 | 17 |
18 For performance reasons, not every item in the list is rendered at once; | 18 For performance reasons, not every item in the list is rendered at once; |
19 instead a small subset of actual template elements *(enough to fill the viewport
)* | 19 instead a small subset of actual template elements *(enough to fill the viewport
)* |
20 are rendered and reused as the user scrolls. As such, it is important that all | 20 are rendered and reused as the user scrolls. As such, it is important that all |
21 state of the list template be bound to the model driving it, since the view may | 21 state of the list template be bound to the model driving it, since the view may |
22 be reused with a new model at any time. Particularly, any state that may change | 22 be reused with a new model at any time. Particularly, any state that may change |
23 as the result of a user interaction with the list item must be bound to the mode
l | 23 as the result of a user interaction with the list item must be bound to the mode
l |
24 to avoid view state inconsistency. | 24 to avoid view state inconsistency. |
25 | 25 |
26 __Important:__ `iron-list` must ether be explicitly sized, or delegate scrolling
to an | 26 __Important:__ `iron-list` must either be explicitly sized, or delegate scrollin
g to an |
27 explicitly sized parent. By "explicitly sized", we mean it either has an explici
t | 27 explicitly sized parent. By "explicitly sized", we mean it either has an explici
t |
28 CSS `height` property set via a class or inline style, or else is sized by other | 28 CSS `height` property set via a class or inline style, or else is sized by other |
29 layout means (e.g. the `flex` or `fit` classes). | 29 layout means (e.g. the `flex` or `fit` classes). |
30 | 30 |
31 ### Template model | 31 ### Template model |
32 | 32 |
33 List item templates should bind to template models of the following structure: | 33 List item templates should bind to template models of the following structure: |
34 | 34 |
35 { | 35 { |
36 index: 0, // data index for this item | 36 index: 0, // data index for this item |
37 item: { // user data corresponding to items[index] | 37 item: { // user data corresponding to items[index] |
38 /* user item data */ | 38 /* user item data */ |
39 } | 39 } |
40 } | 40 } |
41 | 41 |
42 Alternatively, you can change the property name used as data index by changing t
he | 42 Alternatively, you can change the property name used as data index by changing t
he |
43 `indexAs` property. The `as` property defines the name of the variable to add to
the binding | 43 `indexAs` property. The `as` property defines the name of the variable to add to
the binding |
44 scope for the array. | 44 scope for the array. |
45 | 45 |
46 For example, given the following `data` array: | 46 For example, given the following `data` array: |
47 | 47 |
48 ##### data.json | 48 ##### data.json |
49 | 49 |
50 [ | 50 ```js |
51 {"name": "Bob"}, | 51 [ |
52 {"name": "Tim"}, | 52 {"name": "Bob"}, |
53 {"name": "Mike"} | 53 {"name": "Tim"}, |
54 ] | 54 {"name": "Mike"} |
| 55 ] |
| 56 ``` |
55 | 57 |
56 The following code would render the list (note the name and checked properties a
re | 58 The following code would render the list (note the name and checked properties a
re |
57 bound from the model object provided to the template scope): | 59 bound from the model object provided to the template scope): |
58 | 60 |
59 <template is="dom-bind"> | 61 ```html |
60 <iron-ajax url="data.json" last-response="{{data}}" auto></iron-ajax> | 62 <template is="dom-bind"> |
61 <iron-list items="[[data]]" as="item"> | 63 <iron-ajax url="data.json" last-response="{{data}}" auto></iron-ajax> |
62 <template> | 64 <iron-list items="[[data]]" as="item"> |
63 <div> | 65 <template> |
64 Name: <span>[[item.name]]</span> | 66 <div> |
65 </div> | 67 Name: <span>[[item.name]]</span> |
66 </template> | 68 </div> |
67 </iron-list> | |
68 </template> | 69 </template> |
| 70 </iron-list> |
| 71 </template> |
| 72 ``` |
69 | 73 |
70 ### Styling | 74 ### Styling |
71 | 75 |
72 Use the `--iron-list-items-container` mixin to style the container of items, e.g
. | 76 Use the `--iron-list-items-container` mixin to style the container of items, e.g
. |
73 | 77 |
74 iron-list { | 78 ```css |
75 --iron-list-items-container: { | 79 iron-list { |
76 margin: auto; | 80 --iron-list-items-container: { |
77 }; | 81 margin: auto; |
78 } | 82 }; |
| 83 } |
| 84 ``` |
79 | 85 |
80 ### Resizing | 86 ### Resizing |
81 | 87 |
82 `iron-list` lays out the items when it recives a notification via the `iron-resi
ze` event. | 88 `iron-list` lays out the items when it receives a notification via the `iron-res
ize` event. |
83 This event is fired by any element that implements `IronResizableBehavior`. | 89 This event is fired by any element that implements `IronResizableBehavior`. |
84 | 90 |
85 By default, elements such as `iron-pages`, `paper-tabs` or `paper-dialog` will t
rigger | 91 By default, elements such as `iron-pages`, `paper-tabs` or `paper-dialog` will t
rigger |
86 this event automatically. If you hide the list manually (e.g. you use `display:
none`) | 92 this event automatically. If you hide the list manually (e.g. you use `display:
none`) |
87 you might want to implement `IronResizableBehavior` or fire this event manually
right | 93 you might want to implement `IronResizableBehavior` or fire this event manually
right |
88 after the list became visible again. e.g. | 94 after the list became visible again. e.g. |
89 | 95 |
90 document.querySelector('iron-list').fire('iron-resize'); | 96 ```js |
| 97 document.querySelector('iron-list').fire('iron-resize'); |
| 98 ``` |
91 | 99 |
| 100 ### When should `<iron-list>` be used? |
| 101 |
| 102 `iron-list` should be used when a page has significantly more DOM nodes than the
ones |
| 103 visible on the screen. e.g. the page has 500 nodes, but only 20 are visible at t
he time. |
| 104 This is why we refer to it as a `virtual` list. In this case, a `dom-repeat` wil
l still |
| 105 create 500 nodes which could slow down the web app, but `iron-list` will only cr
eate 20. |
| 106 |
| 107 However, having an `iron-list` does not mean that you can load all the data at o
nce. |
| 108 Say, you have a million records in the database, you want to split the data into
pages |
| 109 so you can bring a page at the time. The page could contain 500 items, and iron-
list |
| 110 will only render 20. |
92 | 111 |
93 @group Iron Element | 112 @group Iron Element |
94 @element iron-list | 113 @element iron-list |
95 @demo demo/index.html Simple list | 114 @demo demo/index.html Simple list |
96 @demo demo/selection.html Selection of items | 115 @demo demo/selection.html Selection of items |
97 @demo demo/collapse.html Collapsable items | 116 @demo demo/collapse.html Collapsable items |
98 --> | 117 --> |
99 | 118 |
100 </head><body><dom-module id="iron-list"> | 119 </head><body><dom-module id="iron-list"> |
101 <template> | 120 <template> |
(...skipping 28 matching lines...) Expand all Loading... |
130 </array-selector> | 149 </array-selector> |
131 | 150 |
132 <div id="items"> | 151 <div id="items"> |
133 <content></content> | 152 <content></content> |
134 </div> | 153 </div> |
135 | 154 |
136 </template> | 155 </template> |
137 </dom-module> | 156 </dom-module> |
138 | 157 |
139 <script src="iron-list-extracted.js"></script></body></html> | 158 <script src="iron-list-extracted.js"></script></body></html> |
OLD | NEW |