0
我有以下jQuery模板,我需要跟蹤應用某些類的迭代次數。我嘗試過所有我能想到的標準JavaScript變體。jQuery模板循環計數器
如何迭代$ i,然後在模板中引用$ i?
<script type="text/html"id="sectionTemplate"> <span data-bind="css: { selected: $data == viewModel.selectedSection() }, click: function(i) { viewModel.selectSection($data) }">
${i++}
<input id="radio" class="ui-helper-hidden-accessible" type="radio" name="radio">
<label class="class${i}" for="radio${i}" aria-pressed="false" role="button" aria-disabled="false">
<span class="ui-button-text">${$data}</span></label>
</span>
jQuery的模板不支持添加邏輯裏面的代碼,如果你需要,即,嘗試其他的模板引擎,比如' doT'或'blueimp' https://github.com/blueimp/JavaScript-Templates – 2011-12-20 18:07:53