Jquery 来自对象迭代的underline.js模板循环

Jquery 来自对象迭代的underline.js模板循环,jquery,templates,underscore.js,underscore.js-templating,Jquery,Templates,Underscore.js,Underscore.js Templating,我有一个模态的以下模板 <div class="ui-modal"> <div class="mask"></div> <div class="ui-modal-container"> <div class="ui-modal-header"> <h3><%= modal['title'] %></h3> </div> <div clas

我有一个模态的以下模板

<div class="ui-modal">
  <div class="mask"></div> 
  <div class="ui-modal-container">
    <div class="ui-modal-header">
      <h3><%= modal['title'] %></h3>
    </div>
    <div class="ui-modal-text">
      <p><%= modal['description'] %></p>
    </div>
    <% if ( modal['buttons'] !== 'undefined' ) { %>
      <div class="ui-button-container">
        <a class="ui-button ui-button-pill <%= modal['buttons'][0]['extra_class'] %> " href="<%= modal['buttons'][0]['href'] %>">
          <span class="label">
            <span class="section"><%= modal['buttons'][0]['label'] %></span> 
          </span>
        </a>
      </div>
    <% } %>
  </div>
</div>

我想要实现的是一个我在其中“硬编码”索引(0)的iteretation。我认为这是一个简单的问题,但不幸的是,我可以找到任何我可以适用于我的情况

任何帮助都将不胜感激

谢谢大家!

下划线模板中
中的内容就是JavaScript。这意味着您可以像在其他任何地方一样迭代数组:
for
-循环

一种典型的方式是:

<% if(modal['buttons']) { %>
  <div class="ui-button-container">
    <% _(model['buttons']).each(function(button) { %>
      <a class="ui-button ui-button-pill <%= button.extra_class %> " href="<%= button.href %>">
        <span class="label">
          <span class="section"><%= button.label %></span> 
        </span>
      </a>
    <% }) %>
  </div>
<% } %>

谢谢你的帮助!这正是我所需要的!:)
<% if(modal['buttons']) { %>
  <div class="ui-button-container">
    <% _(model['buttons']).each(function(button) { %>
      <a class="ui-button ui-button-pill <%= button.extra_class %> " href="<%= button.href %>">
        <span class="label">
          <span class="section"><%= button.label %></span> 
        </span>
      </a>
    <% }) %>
  </div>
<% } %>
<% if(modal['buttons']) { %>
  <div class="ui-button-container">
    <% for(var i = 0; i < model.buttons.length; ++i) { %>
      <a class="ui-button ui-button-pill <%= model.buttons[i].extra_class %> " href="<%= model.buttons[i].href %>">
        <span class="label">
          <span class="section"><%= model.buttons[i].label %></span> 
        </span>
      </a>
    <% } %>
  </div>
<% } %>