knockoutjs:Example 1: テンプレートをforeachで使用:The template binding

  1. <!DOCTYPE html>
  2. <html lang="ja">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>knockoutjs:Example 1: テンプレートをforeachで使用:The template binding</title>
  6. <script type="text/javascript" src="jquery-1.5.1.min.js"></script>
  7. <script type="text/javascript" src="knockout-2.1.0beta.js"></script>
  8. </head>
  9. <body>
  10. <h1>knockoutjs:Example 1: テンプレートをforeachで使用:The template binding</h1>
  11. <h2>Participants</h2>
  12. Here are the participants:
  13. <div data-bind="template: { name: 'person-template', foreach: people }"></div>
  14. <script type="text/html" id="person-template">
  15.   <h3 data-bind="text: name"></h3>
  16.   <p>Credits: <span data-bind="text: credits"></span></p>
  17. </script>
  18.  
  19. <script type="text/javascript">
  20.   function MyViewModel() {
  21.     this.people = [
  22.       { name: 'Franklin', credits: 250 },
  23.       { name: 'Mario', credits: 5800 }
  24.     ]
  25.   }
  26.   ko.applyBindings(new MyViewModel());
  27. </script>
  28. <div style="font-size:10pt;text-align:right;margin-top:0.5em;">
  29. <a href="//tips.recatnap.info/" target="_top">PCスキルの小技・忘却防止メモ</a> -
  30. <a href="//tips.recatnap.info/wiki/" target="_top">PCスキルの小技・忘却防止メモのまとめ(wiki)</a>
  31. </div>
  32. <div style="font-size:10pt;text-align:center;margin-top:0.5em;padding:0.5em;border-top:1px solid #ccc;">
  33. Copyright &copy; 2009 by PCスキルの小技・忘却防止メモ. All rights reserved.
  34. </div>
  35. </body>
  36. </html>