$(function() { /*================================================================ 情報 ================================================================*/ var allList = [ { id: "1813", life: "39.8", url:"index.php?act=staff&id=1813", img:"user_data/11098.jpg", nen:"平成24年式", soukou:"71666", title:"【あ単楽】スズキラパンG茶2891", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1926", life: "128.8", url:"index.php?act=staff&id=1926", img:"user_data/11016.jpg", nen:"令和2年式", soukou:"62261", title:"スペーシアHV X3805", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1938", life: "98.8", url:"index.php?act=staff&id=1938", img:"user_data/11202.jpg", nen:"平成30年式", soukou:"55715", title:"スペーシアG HV3067", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1979", life: "128.8", url:"index.php?act=staff&id=1979", img:"user_data/11209.jpg", nen:"令和2年式", soukou:"31472", title:"スペーシアG HV3081", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "2122", life: "54.8", url:"index.php?act=staff&id=2122", img:"user_data/13351.jpg", nen:"平成26年式", soukou:"53121", title:"ekスペースE3280", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "2174", life: "148.8", url:"index.php?act=staff&id=2174", img:"user_data/13446.jpg", nen:"令和4年式", soukou:"13300", title:"スペーシアG HV3360", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "2454", life: "98.8", url:"index.php?act=staff&id=2454", img:"user_data/13755.jpg", nen:"令和1年式", soukou:"70801", title:"N-BOX Gホンダセンシング青", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "2455", life: "98.8", url:"index.php?act=staff&id=2455", img:"user_data/13750.jpg", nen:"令和1年式", soukou:"68761", title:"N-BOX Gホンダセンシング青", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "2464", life: "98.8", url:"index.php?act=staff&id=2464", img:"user_data/13834.jpg", nen:"平成28年式", soukou:"79148", title:"N-BOXカスタム G Lパッケージ青", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "2465", life: "88.8", url:"index.php?act=staff&id=2465", img:"user_data/13820.jpg", nen:"平成28年式", soukou:"52041", title:"N-BOXピンク1096 G Lパッケージ", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "2466", life: "88.8", url:"index.php?act=staff&id=2466", img:"user_data/13826.jpg", nen:"平成28年式", soukou:"67917", title:"車イス仕様車N-BOXピンク プラスG Lパッケージ", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "2467", life: "88.8", url:"index.php?act=staff&id=2467", img:"user_data/13828.jpg", nen:"平成28年式", soukou:"73949", title:"ウェイクD_SA2オレンジ1101", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "2470", life: "128.8", url:"index.php?act=staff&id=2470", img:"user_data/13831.jpg", nen:"平成31年式", soukou:"78088", title:"スペーシアカスタム黄1097HYBRID XS", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "2475", life: "98.8", url:"index.php?act=staff&id=2475", img:"user_data/13835.jpg", nen:"平成29年式", soukou:"42368", title:"N-BOX青1073 G SSパッケージ", sold:"", new:"", tag: ["","","","AT","売り切れ"], description: "tesut" }, { id: "2476", life: "98.8", url:"index.php?act=staff&id=2476", img:"user_data/13832.jpg", nen:"平成27年式", soukou:"42437", title:"N-BOXカスタム赤1098G Lパッケージ2トーンカラースタイル", sold:"", new:"", tag: ["新着","","","AT","売り切れ"], description: "tesut" }, { id: "2477", life: "98.8", url:"index.php?act=staff&id=2477", img:"user_data/13822.jpg", nen:"平成29年式", soukou:"37700", title:"ムーブキャンパスX1092メイクアップSA IIミント", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "2478", life: "128.8", url:"index.php?act=staff&id=2478", img:"user_data/13839.jpg", nen:"平成30年式", soukou:"56276", title:"スペーシアカスタム青HYBRID GS", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "2483", life: "98.8", url:"index.php?act=staff&id=2483", img:"user_data/13815.jpg", nen:"平成31年式", soukou:"54239", title:"タントカスタム黒1099RSトップエディション VS SA3", sold:"", new:"", tag: ["新着","","","AT","売り切れ"], description: "tesut" }, { id: "2484", life: "88.8", url:"index.php?act=staff&id=2484", img:"user_data/13816.jpg", nen:"平成27年式", soukou:"58537", title:"N-BOXピンク1115 G Lパッケージ", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "2485", life: "118.8", url:"index.php?act=staff&id=2485", img:"user_data/13823.jpg", nen:"平成27年式", soukou:"30395", title:"N-BOXスラッシュ1093X水色ターボパッケージ", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "2489", life: "88.8", url:"index.php?act=staff&id=2489", img:"user_data/13836.jpg", nen:"平成27年式", soukou:"74219", title:"N-BOXスラッシュ白Xターボパッケージ", sold:"", new:"", tag: ["","","","AT","売り切れ"], description: "tesut" }, { id: "2496", life: "88.8", url:"index.php?act=staff&id=2496", img:"user_data/14134.jpg", nen:"平成24年式", soukou:"44290", title:"N-BOXカスタム白1171 G Lパッケージ", sold:"", new:"", tag: ["","","","AT","売り切れ"], description: "tesut" }, { id: "2497", life: "78.8", url:"index.php?act=staff&id=2497", img:"user_data/14149.jpg", nen:"平成25年式", soukou:"72016", title:"N-BOXカスタム銀1185 G Lパッケージ", sold:"", new:"", tag: ["新着","","","AT","売り切れ"], description: "tesut" }, { id: "2498", life: "39.8", url:"index.php?act=staff&id=2498", img:"user_data/14179.jpg", nen:"平成25年式", soukou:"90790", title:"ワゴンRスティングレーX紫", sold:"", new:"", tag: ["","","","AT","売り切れ"], description: "tesut" }, { id: "2499", life: "78.8", url:"index.php?act=staff&id=2499", img:"user_data/14180.jpg", nen:"平成28年式", soukou:"54431", title:"タントX SA3赤", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "2503", life: "78.8", url:"index.php?act=staff&id=2503", img:"user_data/14231.jpg", nen:"平成24年式", soukou:"33481", title:"N-BOXプラス青G Lパッケージ", sold:"", new:"", tag: ["新着","","","AT","売り切れ"], description: "tesut" }, { id: "2504", life: "78.8", url:"index.php?act=staff&id=2504", img:"user_data/14229.jpg", nen:"平成25年式", soukou:"62440", title:"タントカスタムXワイン8787 SA", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "2507", life: "108.8", url:"index.php?act=staff&id=2507", img:"user_data/14240.jpg", nen:"平成29年式", soukou:"55260", title:"タントカスタムX白8510", sold:"", new:"", tag: ["","","","AT","売り切れ"], description: "tesut" }, { id: "2508", life: "98.8", url:"index.php?act=staff&id=2508", img:"user_data/14241.jpg", nen:"平成29年式", soukou:"55240", title:"スペーシアカスタム白HYBRIDカスタムZ Zターボ", sold:"", new:"", tag: ["","","","AT","売り切れ"], description: "tesut" }, { id: "2518", life: "148.8", url:"index.php?act=staff&id=2518", img:"user_data/15148.jpg", nen:"令和1年式", soukou:"42672", title:"スペーシアギアHYBRID XZターボ", sold:"", new:"", tag: ["","","","AT","売り切れ"], description: "tesut" }, { id: "2561", life: "78.8", url:"index.php?act=staff&id=2561", img:"user_data/15735.jpg", nen:"令和1年式", soukou:"34405", title:"ekワゴン銀1709", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "2568", life: "78.8", url:"index.php?act=staff&id=2568", img:"user_data/15875.jpg", nen:"令和1年式", soukou:"35763", title:"ekワゴン銀1707", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "2586", life: "78.8", url:"index.php?act=staff&id=2586", img:"user_data/15922.jpg", nen:"令和1年式", soukou:"32650", title:"ekワゴン銀1501", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "2587", life: "78.8", url:"index.php?act=staff&id=2587", img:"user_data/15932.jpg", nen:"令和1年式", soukou:"30407", title:"ekワゴン白", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "2590", life: "78.8", url:"index.php?act=staff&id=2590", img:"user_data/15934.jpg", nen:"平成29年式", soukou:"61065", title:"スバル シフォン赤", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "2599", life: "78.8", url:"index.php?act=staff&id=2599", img:"user_data/15943.jpg", nen:"平成28年式", soukou:"54556", title:"タントX赤", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1477", life: "39.8", url:"index.php?act=staff&id=1477", img:"user_data/9668.jpg", nen:"平成24年式", soukou:"93218", title:"【あ単】ニッサンモコS赤2562", sold:"", new:"", tag: ["","","","AT","売り切れ"], description: "tesut" }, { id: "1455", life: "29.8", url:"index.php?act=staff&id=1455", img:"user_data/9654.jpg", nen:"平成25年式", soukou:"100047", title:"【あ単じ】ニッサンモコS アロマティックアクア2374", sold:"", new:"", tag: ["","","","AT","売り切れ"], description: "tesut" }, { id: "1432", life: "29.8", url:"index.php?act=staff&id=1432", img:"user_data/9623.jpg", nen:"平成24年式", soukou:"99416", title:"【あ単じ】ニッサン モコ S茶2393", sold:"", new:"", tag: ["","","","AT","売り切れ"], description: "tesut" }, { id: "1419", life: "49.8", url:"index.php?act=staff&id=1419", img:"user_data/9650.jpg", nen:"平成26年式", soukou:"64724", title:"【あ単楽】スズキラパンG薄緑2494", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "2611", life: "98.8", url:"index.php?act=staff&id=2611", img:"./img/nophoto.png", nen:"平成30年式", soukou:"27358", title:"タントL銀 SA3", 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(); });