空データの追加

  1. <!DOCTYPE html>
  2. <html lang="ja">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>空データの追加</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. <script type="text/javascript">
  9.   $(document).ready(function () {
  10.     function viewModel() {
  11.       var self = this;
  12.       // 表示するデータ群をいれる変数(?)
  13.       self.tourism = ko.observableArray();
  14.       // 表示するデータ
  15.       self.tourism([
  16.         { local: '九州地方', area: '太宰府', kind: '歴史遺産', description: '太宰府天満宮、大宰府政庁跡。', },
  17.         { local: '東北地方', area: '大仙市', kind: '文化・自然・温泉', description: '大曲花火大会、秋ノ宮温泉郷など。', },
  18.         { local: '北海道', area: '七飯', kind: '自然・保養', description: '大沼・小沼などの大沼国定公園、流山温泉。', },
  19.         { local: '沖縄地方', area: '恩納', kind: '保養地・自然', description: 'ビーチリゾート、万座毛。', },
  20.         { local: '北海道', area: '旭川', kind: '文化', description: 'アイヌ文化、旭山動物園など。', },
  21.         { local: '九州地方', area: '指宿', kind: '保養・自然', description: '指宿温泉、開聞岳、池田湖、長崎鼻。', },
  22.         { local: '九州地方', area: '鹿児島', kind: '歴史遺産・自然', description: '桜島、磯庭園、城山など。', },
  23.         { local: '関東地方', area: '箱根', kind: '保養', description: '箱根温泉、芦ノ湖、箱根駅伝。', },
  24.         { local: '中部地方', area: '黒部', kind: '自然・温泉', description: '宇奈月温泉などの温泉、黒部峡谷。', },
  25.         { local: '中部地方', area: '名古屋', kind: '歴史遺産・文化', description: '名古屋城、熱田神宮、徳川美術館', },
  26.         { local: '四国地方', area: '大洲', kind: '町並・歴史遺産', description: 'おはなはん通り、大洲城、鵜飼など。', },
  27.         { local: '中国地方', area: '米子', kind: '保養・歴史遺産', description: '皆生温泉、米子城跡と城下町', },
  28.         { local: '中国地方', area: '出雲市', kind: '自然・歴史遺産', description: '出雲大社、日御碕、立久恵峡など。', },
  29.         { local: '沖縄地方', area: '南城市知念地区', kind: '歴史遺産', description: '世界遺産である斎場御嶽。', },
  30.       ]);
  31.       // 空データを追加する
  32.       self.addRecord = function()
  33.       {
  34.         // 追加するデータ(オブジェクト):空データで良いので値は無し。
  35.         var data = { local: '', area: '', kind: '', description: '', };
  36.         self.tourism.push(data);
  37.       };
  38.     }
  39.     ko.applyBindings(new viewModel());
  40.   });
  41. </script>
  42. <style type="text/css">
  43. th, td{
  44.   border:1px solid #ccc;
  45.   font-size:small;
  46. }
  47. </style>
  48. </head>
  49. <body>
  50. <h1>空データの追加</h1>
  51. <table>
  52. <thead>
  53. <tr>
  54. <th>地方</th>
  55. <th>地域</th>
  56. <th>種別</th>
  57. <th>説明</th>
  58. </tr>
  59. </thead>
  60. <tbody data-bind="foreach: tourism">
  61. <tr>
  62. <td style="white-space:nowrap" data-bind="text: local"></td>
  63. <td style="white-space:nowrap" data-bind="text: area"></td>
  64. <td style="white-space:nowrap" data-bind="text: kind"></td>
  65. <td data-bind="text: description"></td>
  66. </tr>
  67. </tbody>
  68. </table>
  69. <button type="button" data-bind="click: addRecord">追加</button>
  70. <div style="font-size:10pt;text-align:right;margin-top:0.5em;">
  71. <a href="//tips.recatnap.info/" target="_top">PCスキルの小技・忘却防止メモ</a> -
  72. <a href="//tips.recatnap.info/wiki/" target="_top">PCスキルの小技・忘却防止メモのまとめ(wiki)</a>
  73. </div>
  74. <div style="font-size:10pt;text-align:center;margin-top:0.5em;padding:0.5em;border-top:1px solid #ccc;">
  75. Copyright &copy; 2009 by PCスキルの小技・忘却防止メモ. All rights reserved.
  76. </div>
  77. </body>
  78. </html>