2010-11-18 9 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

या

ए) answer1, बी) answer2, c) answer3

मुझे क्या करना चाहिए?

उत्तर

21

वहाँ एक अंतर्निहित $index (और $value) {{each}} loop के अंदर उपलब्ध है, तो आप उपयोग कर सकते हैं कि यहाँ है:

<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> 

आप शायद 1 जोड़ना चाहें, क्योंकि यह 0 आधारित है, जैसे मैं ऊपर है।

संबंधित मुद्दे