_.each()中的多个值

时间:2017-11-07 00:44:09

标签: javascript html underscore.js clndr.js

所以我想在第5行从不同的iteratees(day.classes和event.part)应用两个值。但它不起作用,我的语法错了吗?

<div class="days">
  <div class="headers">
    <% _.each(daysOfTheWeek, function(day) { %><div class="day-header"><%= day %></div><% }); %>
  </div>
  <% _.each([days, eventsThisMonth] function([day, event]) { %><div class="<%= day.classes %> <%= event.part %>" id="<%= day.id %>"><%= day.day %></div><% }); %>
</div>
<div class="events">
  <div class="headers">
    <div class="x-button">✖</div>
    <div class="event-header">EVENTS</div>
  </div>
  <div class="events-list">
    <% _.each(eventsThisMonth, function(event) { %>
      <div class="event">
        <a href="<%= event.url %>"><%= moment(event.date).format('MMMM Do') %>: <%= event.times %> <%= event.part %></a>
      </div>
    <% }); %>
  </div>
</div>

1 个答案:

答案 0 :(得分:0)

从第5行的回调函数参数中删除方括号,它应该可以正常工作。方括号将您的参数转换为数组。

变化:

function([day, event])

要:

function(day, event)