开发者

for x = 0 to N in jQuery Templates [closed]

开发者 https://www.devze.com 2023-03-11 07:20 出处:网络
开发者_JAVA技巧 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form.
开发者_JAVA技巧 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号