それ以外の場合は静的なアイテムのリストで特定のキーワード ボタンを使用して、単純な絞り込みフィルターを作成しようとしています。
ボタンは順序付けされていないリストにあり、選択するとクラス「.selected-tag-button」が追加されます。
アイテムは、クラス「.item」の div であり、アクティブなときにクラス「.included-item」を取得します。div 内には、ボタンのテキスト ノードに一致するキーワードを含むリスト アイテムを含む別の UL があります。
現在、クリックされたボタンのキーワードのみを含む「buttonName」を使用する代わりに、選択したすべてのキーワードの配列を含む「buttonArray」を使用したいと考えています。
何らかの機能が必要になると思いますが、どこから始めればよいかわかりません。複数のキーワードが選択されている場合、選択したすべてのキーワードを含む項目のみに結果を限定したいと考えています。私が理解できたすべてのソリューションは、配列内のキーワードのいずれかを含む div を返します。
$(document).ready(function() {
$("li.tag-button").on("click", function() {
// Toggle button
$(this).toggleClass("selected-tag-button");
// Remove included-item class from all items
$(".item" ).removeClass("included-item");
// Pass the button text into variable
var buttonName = $(this).text().slice(2);
// Create array with button text for all active buttons
var buttonArray = $(".selected-tag-button").map(function() {
return $(this).text().slice(2);
}).get();
console.log(buttonArray);
// Add included-item class to divs containing the button text
$('li:contains("' + buttonName + '")').parents().parents().addClass("included-item");
// If all buttons are inactive, add included-item class to all items
if ($(".selected-tag-button").length == 0 ) {
$(".item" ).addClass("included-item");
}
});
});