Example 2: eventバインディング:foreachやwith内でのマウスオーバー
- <!DOCTYPE html>
- <html lang="ja">
- <head>
- <meta charset="UTF-8">
- <title>Example 2: eventバインディング:foreachやwith内でのマウスオーバー</title>
- <script type="text/javascript" src="knockout-2.1.0beta.js"></script>
- </head>
- <body>
- <h1>Example 2: eventバインディング:foreachやwith内でのマウスオーバー</h1>
- <ul data-bind="foreach: places">
- <li data-bind="text: $data, event: { mouseover: $parent.logMouseOver }"> </li>
- </ul>
- <p>You seem to be interested in: <span data-bind="text: lastInterest"> </span></p>
- <script type="text/javascript">
- function MyViewModel() {
- var self = this;
- self.lastInterest = ko.observable();
- self.places = ko.observableArray(['London', 'Paris', 'Tokyo']);
- // The current item will be passed as the first parameter, so we know which place was hovered over
- self.logMouseOver = function(place) {
- self.lastInterest(place);
- }
- }
- ko.applyBindings(new MyViewModel());
- </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>