我有一个在内部 div 中有标签的帖子链接列表。用户从三个不同的列表中选择来过滤帖子。
基本上我想要实现的是基于用户选择的三个列表的内容进行前端过滤。
我希望逻辑基本上是这样的:IF post-tags-list has 1+ item from list1 AND has 1+ item from list2 AND has 1+ item from list3, THEN keep the post
下面是我作为开始的内容,但是IF
如果有人没有从其中一个列表中选择任何内容,我需要大量的陈述来说明目前的情况。我知道使用开关可能会更容易,但我不完全确定我的逻辑是否正确。
$(".post-link").each(function(index){
//Get all the post's terms from its hidden tag div and store in an array
var terms = $(this).find(".tags").attr('class').split(" ");
//Cut off the first two items ('hidden' and 'tags')
terms.splice(0,2);
//If interests is set
if(typeof interests[0] != 'undefined'){
var found = 0;
var keep = false;
//For each of the selected interests...
$.each(interests, function(index, value){
//For each of the posts terms
$.each(terms, function(index2, value2){
//If the posts has a selected interest, keep it
if(value == value2){ keep=true;}
});
});
//After all that, if we couldn't find anything...
if(keep!=true){
//Hide the post (.post-link)
$(this).hide();
}
}
//THE ABOVE ONLY ACCOUNTS FOR IF SOMETHING IS SELECTED FOR THE FIRST LIST
//I'M NOT SURE HOW I WOULD IMPLEMENT THIS ACROSS TWO OTHER LISTS
});
如果您需要更多信息,请告诉我。
谢谢!