简体   繁体   English

Underscore.js检查一个数组的值是否等于另一个数组中的项

[英]Underscore.js check if an array value is equal to an item in another array

I have the following underscore.js template. 我有以下underscore.js模板。 I want to check if an array value is equal to date in the pubHols array. 我想检查一个数组值是否等于pubHols数组中的日期。 Whats the syntax to do this? 这样做的语法是什么?

var pubHols = [
     { date: '2015-12-25', title: 'Christmas Day' },
     { date: '2015-12-28', title: 'Boxing Day' },

 ];



  <% _.each(days, function(day) { %>
    <% if(day.date == pubHols.date){ %>
      <div class="pubHol"><span class="day-number"><%= day.day %></span></div>
    <% } %>
  <% }); %>

您可以使用findWhere

<% if(_.findWhere(pubHols, { date: day.date })){ %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM