HOME > > > >

{{each}} Template Tag

{{each( index, value ) collection}} content {{/each}}

引数

(number)index
繰り返し内で$indexで参照できる
(mixed)value
繰り返し内で$valueで参照できる
(array|object)collection

テンプレートタグ。テンプレート内で繰り返しを実行する。

サンプル

実行結果

Javascript

  1. $('#template-1')
  2. .tmpl([
  3.     { name: 'API', data: [
  4.                          'jQuery Core',
  5.                          'Selectors',
  6.                          'Attributes',
  7.                          '',
  8.                          'Traversing',
  9.                          'Manipulation',
  10.                          'CSS',
  11.                          false,
  12.                          'Events',
  13.                          'Effects',
  14.                          'Ajax',
  15.                          null,
  16.                          'Utilities',
  17.                          'Internals'
  18.                          ]},
  19. ]).appendTo('.jqTest1 .screen');

HTML

  1. <div class="jqTest1">
  2.     <script id="template-1" type="text/x-jquery-tmpl">
  3.         <dl>
  4.         <dt>{{= name}}</dt>
  5.         {{each data}}
  6.             {{if $value}}
  7.                 <dd>{{= $value}}</dd>
  8.             {{/if}}
  9.         {{/each}}
  10.         </dl>
  11.     </script>
  12.  
  13.     <div class="screen"></div>
  14. </div>