【发布时间】:2020-08-11 12:51:45
【问题描述】:
您好,我正在尝试执行 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>
【问题讨论】:
-
那么...您想收集唯一的
location.locations 及其匹配数吗? -
是的!因此,如果值相同,那么它将填充到 .class-location div 中并显示该特定匹配的匹配数。
标签: jquery wordpress if-statement filter jquery-selectors