2010-11-18 8 views
7

に私はjQueryのテンプレートプラグインを使用しています取得し、アイテムのインデックスを取得する方法がわからない:私が見せたいインデックスは、jQueryのテンプレート

<script id="optionTmpl" type="text/x-jquery-tmpl"> 
    <table width="100%" border="0" cellspacing="0" cellpadding="0"> 
    {{each Answers}} 
     <tr> 
      <th><input type="radio" name="group1" value="${this.AnswerID}" /></th> 
      <td>${this.AnswerText}</td><!-- add number in this line---> 
     </tr> 
    {{/each}} 
    </table> 
</script> 

:ここ http://api.jquery.com/category/plugins/templates/

を私のコードです以下

1)ANSWER1ような形式で答え、2)ANSWER2、3)ANSWER3

又は

a)回答1、b)回答2、c)回答3

どうすればよいですか? {{each}} loop内部$index暗黙の(そして$value)利用できるがあります

答えて

21

、あなたはここに使用することができます。

<script id="optionTmpl" type="text/x-jquery-tmpl"> 
    <table width="100%" border="0" cellspacing="0" cellpadding="0"> 
    {{each Answers}} 
     <tr> 
      <th><input type="radio" name="group1" value="${this.AnswerID}" /></th> 
      <td>${this.AnswerText} ${$index + 1}</td> 
     </tr> 
    {{/each}} 
    </table> 
</script> 

をあなたはおそらく、私は上記の持っているように、それは、0ベースだから1を追加したいと思うでしょう。

関連する問題