improve docs on redrawing and keys
This commit is contained in:
parent
eceea4addf
commit
57e9e1557e
4 changed files with 52 additions and 5 deletions
|
|
@ -9,6 +9,7 @@
|
|||
[Destructors](#destructors)
|
||||
[SVG](#svg)
|
||||
[Dealing with focus](#dealing-with-focus)
|
||||
[Dealing with sorting and deleting in lists](#dealing-with-sorting-and-deleting-in-lists)
|
||||
[Signature](#signature)
|
||||
|
||||
---
|
||||
|
|
@ -321,6 +322,24 @@ m("li", {class: selected ? "active" : ""})
|
|||
|
||||
---
|
||||
|
||||
### Dealing with sorting and deleting in lists
|
||||
|
||||
As with input focus, we can maintain referential integrity between data in a list and the respective DOM representation by using keys.
|
||||
|
||||
```javascript
|
||||
m("ul", [
|
||||
ctrl.items.map(function(item) {
|
||||
return m("li", {key: item.id}, [
|
||||
m("input")
|
||||
]);
|
||||
})
|
||||
]);
|
||||
```
|
||||
|
||||
You should always use keys if you need to sort lists, remove items from them or splice them in any way.
|
||||
|
||||
---
|
||||
|
||||
### Signature
|
||||
|
||||
[How to read signatures](how-to-read-signatures.md)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue