0
こんにちはstackoverflowのユーザー属性操作し、フィルタリングする私は私をしたいと思い、それらのcriteriasの一つは、ユーザによって適用されたとき、私は、4つのcriteriasによってフィルタリングれますジョブリストを作成したいと考え、複数のHTMLデータが
をjQueryのを使用してjQueryライブによってフィルタリングされるリストと、正しい結果を更新して表示するリスト。
は、私のコードのを見てみましょう:
A)HTMLフィルタ
<select id="country">
<option>Italy</option>
<option>France</option>
....
</select>
<select id="industry">
<option>Finance</option>
<option>Internet</option>
....
</select>
<select id="remote">
<option>Yes</option>
<option>No</option>
....
</select>
<select id="sponsor-visas">
<option>Yes</option>
<option>No</option>
....
</select>
B)HTMLのジョブリストを
<div class="job-container" data-country="Italy" data-industry="Finance" data-remote="Yes" data-sponsor-visa="No">
//Here the content of a job eg: Images, Title and etc.
</div>
<div class="job-container" data-country="France" data-industry="Internet" data-remote="No" data-sponsor-visa="Yes">
//Here the content of a job eg: Images, Title and etc.
</div>
<div class="job-container" data-country="Spain" data-industry="Finance" data-remote="Yes" data-sponsor-visa="No">
//Here the content of a job eg: Images, Title and etc.
</div>
and goes on....
C)jQueryの
var filters = [];
$('#industry').on('change', function(){
var value = $(this).val();
filters['industry'] = value;
filteredResults();
});
$('#country').on('change', function(){
var value = $(this).val();
filters['country'] = value;
filteredResults();
});
$('#remote').on('change', function(){
var value = $(this).val();
filters['remote'] = value;
filteredResults();
});
$('#sponsor-visas').on('change', function(){
var value = $(this).val();
filters['visa'] = value;
filteredResults();
});
function filteredResults() {
$('.job-container').each(function(){
var industry = $(this).attr('data-industry');
var remote = $(this).attr('data-remote');
var visa = $(this).attr('data-visa');
var country = $(this).attr('data-country');
if (filters['industry'] == industry) { // HERE I WOULD LIKE TO DO THE SAME WITH ALL FILTERS
$(this).fadeIn('fast');
}
else {
$(this).fadeOut('fast');
}
});
}
だから何私が望むのは、ユーザーが選択したときです前によるフィルタの国は、すでに私は解決策
を見つけることを願って、フィルタ業界を保持し、同じ業界と国 私の英語のため申し訳ありませんを持って仕事にリストを更新するために変化に
をフィルタ業界を選択しています
残念なことに、うまくいないようです:( – Vasileios
btwありがとうございました,,,,,この関数は私が必要とするものに非常に近いと思われますが、私はこの関数で解決策を見つけようとします。 – Vasileios
あまりデータがありません一緒に仕事をするここで合理的にうまく動作するように努力しています。https://jsfiddle.net/4vknLoa9/2 – charlietfl