knockoutjs:Example 1: 基本的な書式:The custom binding

  1. <!DOCTYPE html>
  2. <html lang="ja">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>knockoutjs:Example 1: 基本的な書式:The custom 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: 基本的な書式:The custom binding</h1>
  11. 基本的な書式なので動きは無し。
  12. <pre>
  13. &lt;body>
  14. &lt;div data-bind="yourBindingName: someValue"> &lt;/div>
  15. &lt;script type="text/javascript">
  16. ko.bindingHandlers.yourBindingName = {
  17.   init: function(element, valueAccessor, allBindingsAccessor, viewModel) {
  18.     // This will be called when the binding is first applied to an element
  19.     // Set up any initial state, event handlers, etc. here
  20.   },
  21.   update: function(element, valueAccessor, allBindingsAccessor, viewModel) {
  22.     // This will be called once when the binding is first applied to an element,
  23.     // and again whenever the associated observable changes value.
  24.     // Update the DOM element based on the supplied values here.
  25.   }
  26. };
  27. &lt;/script>
  28. &lt;/body>
  29. </pre>
  30. <div style="font-size:10pt;text-align:right;margin-top:0.5em;">
  31. <a href="//tips.recatnap.info/" target="_top">PCスキルの小技・忘却防止メモ</a> -
  32. <a href="//tips.recatnap.info/wiki/" target="_top">PCスキルの小技・忘却防止メモのまとめ(wiki)</a>
  33. </div>
  34. <div style="font-size:10pt;text-align:center;margin-top:0.5em;padding:0.5em;border-top:1px solid #ccc;">
  35. Copyright &copy; 2009 by PCスキルの小技・忘却防止メモ. All rights reserved.
  36. </div>
  37. </body>
  38. </html>