knockoutjs:Example 1: 親が真なら子・孫のバインディングは無効:The custom binding Control descendant bindings
- <!DOCTYPE html>
- <html lang="ja">
- <head>
- <meta charset="UTF-8">
- <title>knockoutjs:Example 1: 親が真なら子・孫のバインディングは無効:The custom binding Control descendant bindings</title>
- <script type="text/javascript" src="jquery-1.5.1.min.js"></script>
- <script type="text/javascript" src="knockout-2.1.0beta.js"></script>
- </head>
- <body>
- <h1>Example 1: 親が真なら子・孫のバインディングは無効:The custom binding Control descendant bindings</h1>
- <div data-bind="allowBindings: true">
- <!-- This will display Replacement, because bindings are applied -->
- <div data-bind="text: 'Replacement'">Original</div>
- </div>
-
- <div data-bind="allowBindings: false">
- <!-- This will display Original, because bindings are not applied -->
- <div data-bind="text: 'Replacement'">Original</div>
- </div>
- <script type="text/javascript">
- ko.bindingHandlers.allowBindings = {
- init: function(elem, valueAccessor) {
- // Let bindings proceed as normal *only if* my value is false
- var shouldAllowBindings = ko.utils.unwrapObservable(valueAccessor());
- return { controlsDescendantBindings: !shouldAllowBindings };
- }
- };
- var viewModel = {};
- ko.applyBindings(viewModel);
- </script>
- <div style="font-size:10pt;text-align:right;margin-top:0.5em;">
- <a href="//tips.recatnap.info/" target="_top">PCスキルの小技・忘却防止メモ</a> -
- <a href="//tips.recatnap.info/wiki/" target="_top">PCスキルの小技・忘却防止メモのまとめ(wiki)</a>
- </div>
- <div style="font-size:10pt;text-align:center;margin-top:0.5em;padding:0.5em;border-top:1px solid #ccc;">
- Copyright © 2009 by PCスキルの小技・忘却防止メモ. All rights reserved.
- </div>
- </body>
- </html>