Jquery匹配值

问题描述 投票:0回答:1

[嗨,我正在尝试执行if语句,以查看值是否在数组中完全匹配。然后,我希望它的兄弟元素显示确切匹配的html。有人可以帮忙吗!我将TWIG用于高级自定义字段Wordpress插件的HTML。 Image of all the locations that I want to say only once with the number of times they are mentioned.这是用于过滤器功能的。最终希望使用https://codepen.io/luciopaiva/pen/YXYGYE?editors=101之类的带有位置标签的下拉菜单。

Jquery

 //exact match
 $(".filter-dropdown .course-location").each(function(i,e) {
  myDivObj = $(this).val() == $(this).val();
    if ($(this).val() == $(this).val()) {
      console.log()
      $(this).parent('.filter-dropdown').siblings('.class-location').children('h4').html(myDivObj);
      $(this).parent('.filter-dropdown').siblings('.class-location').children('span').html($(".course-location").length);
    }
    else {

      console.log('unknown');
    }
  });

HTML

             <div class="filter" id="course-location">
              <div class="upper-filter"><h3>Locations</h3><i class="fas fa-angle-down"></i></div>
              {% for category in bloc.training_course_list_compact.course_categories %}
              {% for locationcourse in category.get_field('courses') %}
              {% for location in locationcourse.get_field('dates') %}
              <div class="filter-dropdown">
                <div class="course-location" value="{{ location.location }}"></div>
              </div>
              {% endfor %}
              {% endfor %}
              {% endfor %}
                <div class="class-location"><h4></h4><p></p><span></span></div>
            </div>

[嗨,我正在尝试执行if语句,以查看值是否在数组中完全匹配。然后,我希望它的兄弟元素显示确切匹配的html。有人可以帮忙吗!我用...

jquery wordpress if-statement filter jquery-selectors
1个回答
0
投票

所以我先使用.map收集所有值,然后将.map收集到格式为.reduce的对象中。最后,您可以创建html元素并将其插入dom。

© www.soinside.com 2019 - 2024. All rights reserved.