| OLD | NEW |
| (Empty) | |
| 1 iron-list |
| 2 ======================== |
| 3 |
| 4 `iron-list` displays a virtual, *'infinite'* list. The template inside |
| 5 the iron-list element represents the DOM to create for each list item. |
| 6 The `items` property specifies an array of list item data. |
| 7 |
| 8 For performance reasons, not every item in the list is rendered at once; |
| 9 instead a small subset of actual template elements *(enough to fill the viewport
)* |
| 10 are rendered and reused as the user scrolls. As such, it is important that all |
| 11 state of the list template be bound to the model driving it, since the view may |
| 12 be reused with a new model at any time. Particularly, any state that may change |
| 13 as the result of a user interaction with the list item must be bound to the mode
l |
| 14 to avoid view state inconsistency. |
| 15 |
| 16 __Important:__ `iron-list` must ether be explicitly sized, or delegate scrolling
to an |
| 17 explicitly sized parent. By "explicitly sized", we mean it either has an explici
t |
| 18 CSS `height` property set via a class or inline style, or else is sized by other |
| 19 layout means (e.g. the `flex` or `fit` classes). |
| 20 |
| 21 ### Template model |
| 22 |
| 23 List item templates should bind to template models of the following structure: |
| 24 |
| 25 ```js |
| 26 { |
| 27 index: 0, // data index for this item |
| 28 item: { // user data corresponding to items[index] |
| 29 /* user item data */ |
| 30 } |
| 31 } |
| 32 ``` |
| 33 |
| 34 Alternatively, you can change the property name used as data index by changing t
he |
| 35 `indexAs` property. The `as` property defines the name of the variable to add to
the binding |
| 36 scope for the array. |
| 37 |
| 38 For example, given the following `data` array: |
| 39 |
| 40 ##### data.json |
| 41 |
| 42 ```js |
| 43 [ |
| 44 {"name": "Bob"}, |
| 45 {"name": "Tim"}, |
| 46 {"name": "Mike"} |
| 47 ] |
| 48 ``` |
| 49 |
| 50 The following code would render the list (note the name and checked properties a
re |
| 51 bound from the model object provided to the template scope): |
| 52 |
| 53 ```html |
| 54 <template is="dom-bind"> |
| 55 <iron-ajax url="data.json" last-response="{{data}}" auto></iron-ajax> |
| 56 <iron-list items="[[data]]" as="item"> |
| 57 <template> |
| 58 <div> |
| 59 Name: <span>[[item.name]]</span> |
| 60 </div> |
| 61 </template> |
| 62 </iron-list> |
| 63 </template> |
| 64 ``` |
| 65 |
| 66 ### Resizing |
| 67 |
| 68 `iron-list` lays out the items when it recives a notification via the `resize` e
vent. |
| 69 This event is fired by any element that implements `IronResizableBehavior`. |
| 70 |
| 71 By default, elements such as `iron-pages`, `paper-tabs` or `paper-dialog` will t
rigger |
| 72 this event automatically. If you hide the list manually (e.g. you use `display:
none`) |
| 73 you might want to implement `IronResizableBehavior` or fire this event manually
right |
| 74 after the list became visible again. e.g. |
| 75 |
| 76 ```js |
| 77 document.querySelector('iron-list').fire('resize'); |
| 78 ``` |
| 79 |
| 80 ### When should `<iron-list>` be used? |
| 81 |
| 82 `iron-list` should be used when a page has significantly more DOM nodes than the
ones visible on the screen. e.g. the page has 500 nodes, but only 20 are visibl
e at the time. This is why we refer to it as a `virtual` list. In this case, a `
dom-repeat` will still create 500 nodes which could slow down the web app, but `
iron-list` will only create 20. |
| 83 |
| 84 However, having an `iron-list` does not mean that you can load all the data at o
nce. Say, you have a million records in the database, you want to split the data
into pages so you can bring a page at the time. The page could contain 500 item
s, and iron-list will only render 20. |
| OLD | NEW |