選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

MIGRATING.md 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # Migrating Guide
  2. ## Moving to mustache.js v2
  3. ### Overview
  4. mustache.js v2 introduces a bug fix that breaks compatibility with older versions: fixing null and undefined lookup.
  5. When mustache.js tries to render a variable `{{name}}`, it executes a `lookup` function to figure out which value it should render. This function looks up the value for the key `name` in the current context, and if there is no such key in the current context it looks up the parent contexts recursively.
  6. Value lookup should stop whenever the key exists in the context. However, due to a bug, this was not happening when the value was `null` or `undefined` even though the key existed in the context.
  7. Here's a simple example of the same template rendered with both mustache.js v1 and v2:
  8. Template:
  9. ```mustache
  10. {{#friends}}
  11. {{name}}'s twitter is: {{twitter}}
  12. {{/friends}}
  13. ```
  14. View:
  15. ```json
  16. {
  17. "name": "David",
  18. "twitter": "@dasilvacontin",
  19. "friends": [
  20. {
  21. "name": "Phillip",
  22. "twitter": "@phillipjohnsen"
  23. },
  24. {
  25. "name": "Jan",
  26. "twitter": null
  27. }
  28. ]
  29. }
  30. ```
  31. Rendered using mustache.js v1:
  32. ```text
  33. Phillip's twitter is: @phillipjohnsen
  34. Jan's twitter is: @dasilvacontin
  35. ```
  36. Rendered using mustache.js v2:
  37. ```text
  38. Phillip's twitter is: @phillipjohnsen
  39. Jan's twitter is:
  40. ```