knockoutjs:Example 2: 表示と非表示:The visible binding

  1. <!DOCTYPE html>
  2. <html lang="ja">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>knockoutjs:Example 2: 表示と非表示:The visible binding</title>
  6. <script type="text/javascript" src="knockout-2.1.0beta.js"></script>
  7. </head>
  8. <body>
  9. <h1>knockoutjs:Example 2: 表示と非表示:The visible binding</h1>
  10. <div data-bind="visible: myValues().length > 0">
  11.   You will see this message only when 'myValues' has at least one member.
  12. </div>
  13. <script type="text/javascript">
  14.   var viewModel = {
  15.     myValues: ko.observableArray([]) // Initially empty, so message hidden
  16.   };
  17.   viewModel.myValues.push("some value"); // Now visible
  18.   ko.applyBindings(viewModel);
  19. </script>
  20. <div style="font-size:10pt;text-align:right;margin-top:0.5em;">
  21. <a href="//tips.recatnap.info/" target="_top">PCスキルの小技・忘却防止メモ</a> -
  22. <a href="//tips.recatnap.info/wiki/" target="_top">PCスキルの小技・忘却防止メモのまとめ(wiki)</a>
  23. </div>
  24. <div style="font-size:10pt;text-align:center;margin-top:0.5em;padding:0.5em;border-top:1px solid #ccc;">
  25. Copyright &copy; 2009 by PCスキルの小技・忘却防止メモ. All rights reserved.
  26. </div>
  27. </body>
  28. </html>