for x = 0 to N in jQuery Templates [closed]
I've started to use jQuery Templates and I think it's great.
I am trying to build a pager. My MVC action returns a JSON object with the current page and the total number of pages. I would like to create a series of buttons. I've seen I can use{{each}}
but it seems that I can only loop in collections.
Is there a way I can loop from currentPage to totalPages and build a series of buttons:
<script id="pagerTmpl" type="text/x-jquery-tmpl">
<input type="radio" id="q_page_" name="radio" /><label for="q_page_">xxx</label>
</script>
I know this code doesn't work but I would like to achieve something like this:
<script id="pagerTmpl" type="text/x-jquery-tmpl">
{{each(currentPage, totalPages)}}
<input type="radio" id="q_page_" name="radio" /><label for="q_page_">xxx</label>
{{/each}}
</script>
Any help will be apreciated.
This works:
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="http://ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js"></script>
</head>
<body>
<script id="pagerTmpl" type="text/x-jquery-tmpl">
{{each page }}
<input type="radio" id="q_page_" name="radio" /><label for="q_page_">xxx</label>
{{/each}}
</script>
<div id="pager"></div>
<script>
/* Render the template with the tmpl data */
$( "#pagerTmpl" ).tmpl( {page:new Array(10)} )
.appendTo( "#pager" );
</script>
</body>
</html>
精彩评论