$(function() { /*================================================================ 情報 ================================================================*/ var allList = [ { id: "964", life: "67.8", url:"index.php?act=staff&id=964", img:"user_data/6814.jpg", nen:"平成24年式", soukou:"81563", title:"シャトルHV白 ホンダ 仕入先→神奈川", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "965", life: "88.8", url:"index.php?act=staff&id=965", img:"user_data/6816.jpg", nen:"平成26年式", soukou:"50847", title:"フィットHV銀 ホンダ 仕入先→神奈川", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "971", life: "ここクリ", url:"index.php?act=staff&id=971", img:"user_data/6800.jpg", nen:"🉐価格", soukou:"🉐価格", title:"SOLING 6.75型VGA ワンセグ Bluetooth対応 カーナビ ", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "958", life: "78.8", url:"index.php?act=staff&id=958", img:"user_data/6797.jpg", nen:"平成26年式", soukou:"117769", title:"シャトルHV銀5351 ホンダ 仕入先→福岡", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "957", life: "77.8", url:"index.php?act=staff&id=957", img:"user_data/6796.jpg", nen:"平成22年式", soukou:"94455", title:"ウイッシュ銀 トヨタ 仕入先→福岡", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "945", life: "78.8", url:"index.php?act=staff&id=945", img:"user_data/6794.jpg", nen:"平成27年式", soukou:"116001", title:"シャトルHV銀5312 ホンダ 仕入先→神奈川", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "932", life: "88.8", url:"index.php?act=staff&id=932", img:"user_data/6609.jpg", nen:"平成24年式", soukou:"103432", title:"フリードHV5352 ホンダ 仕入先→神奈川", sold:"", new:"", tag: ["新着","","","AT","売り切れ"], description: "tesut" }, { id: "930", life: "78.8", url:"index.php?act=staff&id=930", img:"user_data/6615.jpg", nen:"平成26年式", soukou:"110067", title:"シャトルHV銀5300 ホンダ 仕入先→神奈川", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "929", life: "69.8", url:"index.php?act=staff&id=929", img:"user_data/6616.jpg", nen:"平成25年式", soukou:"120667", title:"シャトルHV白5299 ホンダ 仕入先→神奈川", sold:"", new:"", tag: ["新着","","","AT","売り切れ"], description: "tesut" }, { id: "928", life: "クリック", url:"index.php?act=staff&id=928", img:"user_data/6600.jpg", nen:"🉐価格", soukou:"🉐価格", title:"貴方をまもる!!ドライブレコーダー", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "927", life: "ここクリ", url:"index.php?act=staff&id=927", img:"user_data/6599.jpg", nen:"🉐価格", soukou:"🉐価格", title:"パイオニアcarrozzeriaDEH-4400", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "926", life: "クリック", url:"index.php?act=staff&id=926", img:"user_data/6598.jpg", nen:"🉐価格", soukou:"🉐価格", title:"KenwoodドライブレコーダーDRV-MR740", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "925", life: "クリック", url:"index.php?act=staff&id=925", img:"user_data/6597.jpg", nen:"🉐価格", soukou:"🉐価格", title:"WATEXドライブレコーダーDVR-2CAM-R", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "924", life: "ここクリ", url:"index.php?act=staff&id=924", img:"user_data/6596.jpg", nen:"🉐価格", soukou:"🉐価格", title:"YUPITERU ドライブレコーダー DRY-ST3000c", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "923", life: "ここクリ", url:"index.php?act=staff&id=923", img:"user_data/6595.jpg", nen:"🉐価格", soukou:"🉐価格", title:"KenwoodドライブレコーダーDRV-240", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "892", life: "75.8", url:"index.php?act=staff&id=892", img:"user_data/6370.jpg", nen:"平成25年式", soukou:"86090", title:"フィルダー銀5258 トヨタ 仕入先→神奈川", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "868", life: "76.8", url:"index.php?act=staff&id=868", img:"user_data/6227.jpg", nen:"平成26年式", soukou:"117332", title:"フィールダーHV水色5204 仕入先→福岡", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "854", life: "49.8", url:"index.php?act=staff&id=854", img:"user_data/5854.jpg", nen:"平成22年式", soukou:"89531", title:"プレマシーワイン682 マツダ 仕入先→埼玉", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "840", life: "68.8", url:"index.php?act=staff&id=840", img:"user_data/5841.jpg", nen:"平成23年式", soukou:"77336", title:"プレマシーワイン677 マツダ 仕入先→大阪", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "834", life: "54.8", url:"index.php?act=staff&id=834", img:"user_data/5785.jpg", nen:"平成24年式", soukou:"110994", title:"シャトル銀5135 ホンダ 仕入先→大阪", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "816", life: "69.8", url:"index.php?act=staff&id=816", img:"user_data/5655.jpg", nen:"平成23年式", soukou:"100900", title:"ラフェスタ白667 ニッサン", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "814", life: "49.8", url:"index.php?act=staff&id=814", img:"user_data/5705.jpg", nen:"平成22年式", soukou:"105869", title:"エクシーガ黒671 スバル", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "801", life: "69.8", url:"index.php?act=staff&id=801", img:"user_data/5544.jpg", nen:"平成22年式", soukou:"83758", title:"ウイッシュ黒664 トヨタ", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "796", life: "74.8", url:"index.php?act=staff&id=796", img:"user_data/5537.jpg", nen:"平成26年式", soukou:"80744", title:"シャトルHV白5098 ホンダ", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "779", life: "49.8", url:"index.php?act=staff&id=779", img:"user_data/4939.jpg", nen:"平成22年式", soukou:"79083", title:"プレマシーワイン635 マツダ", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "775", life: "49.8", url:"index.php?act=staff&id=775", img:"user_data/4928.jpg", nen:"平成22年式", soukou:"91700", title:"プレマシーワイン633 マツダ", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "766", life: "34.8", url:"index.php?act=staff&id=766", img:"user_data/4919.jpg", nen:"平成22年式", soukou:"106834", title:"フリードグレー4951 ホンダ", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "765", life: "59.8", url:"index.php?act=staff&id=765", img:"user_data/4917.jpg", nen:"平成22年式", soukou:"61684", title:"ウイッシュ銀4954 トヨタ", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "763", life: "55.8", url:"index.php?act=staff&id=763", img:"user_data/4916.jpg", nen:"平成23年式", soukou:"110900", title:"MPV白631 マツダ", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "744", life: "58.8", url:"index.php?act=staff&id=744", img:"user_data/4898.jpg", nen:"平成23年式", soukou:"94370", title:"フリード銀4939ホンダ", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "732", life: "34.8", url:"index.php?act=staff&id=732", img:"user_data/4886.jpg", nen:"平成22年式", soukou:"110300", title:"フリード紺4859 ホンダ", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "702", life: "51.8", url:"index.php?act=staff&id=702", img:"user_data/4803.jpg", nen:"平成22年式", soukou:"88526", title:"エクシーガ黒600 スバル", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "621", life: "54.8", url:"index.php?act=staff&id=621", img:"user_data/4374.jpg", nen:"平成22年式", soukou:"91647", title:"フリード黒4808 ホンダ", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "82", life: "39.8", url:"index.php?act=staff&id=82", img:"user_data/996.jpg", nen:"平成22年式", soukou:"112991", title:"エクシーガ602 スバル", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "993", life: "49.8", url:"index.php?act=staff&id=993", img:"./img/nophoto.png", nen:"平成23年式", soukou:"120991", title:"④HVシャトルブラック仕入先:埼玉", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "999", life: "45.8", url:"index.php?act=staff&id=999", img:"./img/nophoto.png", nen:"平成21年式", soukou:"90300", title:"⑩エクシーガ2.0iブラック仕入先:埼玉", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "1010", life: "49.8", url:"index.php?act=staff&id=1010", img:"./img/nophoto.png", nen:"平成23年式", soukou:"124000", title:"㉑ラフェスタ ハイウェイスターG 黒仕入先:福岡", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "1023", life: "108.8", url:"index.php?act=staff&id=1023", img:"./img/nophoto.png", nen:"平成27年式", soukou:"96572", title:"㉞フリードHV グレー仕入先:兵庫", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "1026", life: "56.8", url:"index.php?act=staff&id=1026", img:"./img/nophoto.png", nen:"平成22年式", soukou:"106000", title:"㊲フリードスパイク Gエアロ ホワイト仕入先:沖縄", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "1028", life: "63.8", url:"index.php?act=staff&id=1028", img:"./img/nophoto.png", nen:"平成22年式", soukou:"79000", title:"㊴フリード G エアロ ブラック仕入先:沖縄", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, ]; /*================================================================ スクリプトはじまり ================================================================*/ function init() { //イベント登録 $(".filter_life select").on("change", onFilterChange); $(".filter_tag input").on("change", onFilterChange); $(".filter_keyword button").on("click", onFilterChange); //最初は全て出力 refleshHtml(allList); } /*================================================================ HTML出力 ================================================================*/ function refleshHtml(list) { var outputHtml = ''; //出力する内容をoutputHtmlに格納 if (list.length > 0) { _.each(list, function(line, i) { outputHtml += '

' + line.title + '

'; outputHtml += '' + line.title + ''; outputHtml += '' + line.new + '' + line.sold + ''; outputHtml += '

価格 ' + line.life + '万円

'; outputHtml += '

年式: ' + line.nen + '

'; outputHtml += '

走行: 約 ' + line.soukou + 'km

'; outputHtml += '
'; }); } else { outputHtml += '

条件に当てはまる車を検索できませんでした。

'; } //HTML出力(フェードインアニメーションつき) $('.productArea').html(outputHtml); $('.productArea .product').css({opacity: 0}).each(function(i){$(this).delay(100 * i).animate({opacity:1}, 300); }); //検索件数表示 $('.productCntArea').html('

' + allList.length + '件中' + list.length + '件を表示しています。

'); } /*================================================================ 絞り込み条件を変更した時 ================================================================*/ function onFilterChange(e) { var filterFncs = []; var result = []; //セレクトボックスの値を引数に指定した関数filterByLifeをfilterFuncs配列に格納 filterFncs.push( function(list) { return filterByLife(list, $('.filter_life select').val()); } ); //チェックボックスの値を引数に指定した関数filterByTagをfilterFuncs配列に格納 filterFncs.push( function(list) { return filterByTag(list, $('.filter_tag input:checked')); } ); //キーワードの値を引数に指定した関数filterByKeywordをfilterFuncs配列に格納 filterFncs.push( function(list) { return filterByKeyword(list, _.escape($('.filter_keyword input').val())); } ); //FilterFuncs配列内の関数をバケツリレーみたいに1つずつ実行して結果をresult配列に格納 result = _.reduce(filterFncs, function(list, fnc) { return fnc(list); }, allList); //絞り込んだ結果を出力 refleshHtml(result); } /*================================================================ 絞り込み[1] セレクトボックス絞り込み関数 ================================================================*/ function filterByLife(list, value) { //絞り込み指定がない場合はリターン if (value == "") { return list; } //選択したセレクトボックスとlifeがマッチするかでフィルタリング return _.filter(list, function(item) { switch (value) { case '1': return item.life <= 10; case '2': return 10 < item.life && item.life <= 20; case '3': return 20 < item.life && item.life <= 30; case '4': return 30 < item.life && item.life <= 40; case '5': return 40 < item.life && item.life <= 50; case '6': return 50 < item.life; } }); } /*================================================================ 絞り込み[2] チェックボックス絞り込み関数 ================================================================*/ function filterByTag(list, value) { //絞り込み指定がない場合はリターン if (value.length == 0) { return list; } //選択した属性(チェックボックス)とtagがマッチするかでフィルタリング return _.filter(list, function(item) { var isMatch = false; //配列同士の比較 _.each(value, function(chkItem, i) { _.each(item.tag, function(tagItem, i) { if (tagItem === $(chkItem).val()) { isMatch = true; } }); }); return isMatch; }); } /*================================================================ 絞り込み[3] テキストボックス絞り込み関数 ================================================================*/ function filterByKeyword(list, value) { //絞り込み指定がない場合はリターン if (value == "") { return list; } //検索キーワードを配列に格納(スペースがある場合は複数格納) var freeAry = [];  var val = value.replace(/ /g, " "); searchAry = val.split(" "); //入力したキーワードがtitleもしくdescriptionにマッチするかでフィルタリング return _.filter(list, function(item) { var isMatch = false; _.each(searchAry, function(data, i) { if (item.title.indexOf(data) != -1 || item.description.indexOf(data) != -1) { isMatch = true; } }); return isMatch; }); } /*================================================================ スクリプトはじめ ================================================================*/ init(); });