$(function() { /*================================================================ 情報 ================================================================*/ var allList = [ { id: "1184", life: "138.8", url:"index.php?act=staff&id=1184", img:"user_data/7927.jpg", nen:"平成30年式", soukou:"22331", title:"カローラフィールダー黒1.5X5670仕入先→神奈川", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "1196", life: "103.8", url:"index.php?act=staff&id=1196", img:"user_data/7930.jpg", nen:"平成29年式", soukou:"63599", title:"シャトルHV銀5692 ホンダ 仕入先→福岡", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "1213", life: "73.8", url:"index.php?act=staff&id=1213", img:"user_data/8236.jpg", nen:"平成28年式", soukou:"64899", title:"アイシスプラタナ790トヨタ 仕入先→沖縄", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1218", life: "83.8", url:"index.php?act=staff&id=1218", img:"user_data/8242.jpg", nen:"平成24年式", soukou:"80138", title:"プリウスα G7名乗り 紺7383仕入先→愛知", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1235", life: "76.8", url:"index.php?act=staff&id=1235", img:"user_data/8274.jpg", nen:"平成27年式", soukou:"66494", title:"カローラフィールダー白1.5X トヨタ仕入先→沖縄", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "1176", life: "73.8", url:"index.php?act=staff&id=1176", img:"user_data/7734.jpg", nen:"平成23年式", soukou:"64971", title:"フリードスパイクハイブリッド G6582 仕入先→大阪", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "1174", life: "73.8", url:"index.php?act=staff&id=1174", img:"user_data/7724.jpg", nen:"平成19年式", soukou:"84127", title:"クロスロード 18L Xパッケージ ホンダ 仕入先→神奈川", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "1171", life: "33.8", url:"index.php?act=staff&id=1171", img:"user_data/7721.jpg", nen:"平成14年式", soukou:"77254", title:"希少車 パジェロミニ スヌーピーエディション2 仕入先→東京", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "1168", life: "38.8", url:"index.php?act=staff&id=1168", img:"user_data/7725.jpg", nen:"平成09年式", soukou:"70734", title:"ステージア25T RS FOUR V 仕入先:栃木", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "1166", life: "38.8", url:"index.php?act=staff&id=1166", img:"user_data/7717.jpg", nen:"平成09年式", soukou:"110,521", title:"ステージア25T RS FOUR V784仕入先:東京", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "1165", life: "68.8", url:"index.php?act=staff&id=1165", img:"user_data/7714.jpg", nen:"平成24年式", soukou:"106235", title:"フリードスパイクHVジャストセレクション5635 仕入先→茨城", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "1160", life: "58.8", url:"index.php?act=staff&id=1160", img:"user_data/7699.jpg", nen:"平成24年式", soukou:"95369", title:"シャトルHVスマートセレクション赤5647 仕入先→愛知", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "1149", life: "58.8", url:"index.php?act=staff&id=1149", img:"user_data/7671.jpg", nen:"平成23年式", soukou:"65892", title:"エクシーガ 2.0i シルバー769 仕入先→愛知", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "1143", life: "43.8", url:"index.php?act=staff&id=1143", img:"user_data/7670.jpg", nen:"平成20年式", soukou:"96888", title:"カローラフィールダー 1.5X Gエディション5639 仕入先→兵庫", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "1141", life: "48.8", url:"index.php?act=staff&id=1141", img:"user_data/7695.jpg", nen:"平成22年式", soukou:"61219", title:"ウィッシュ 1.8X HIDセレクション5631 グレー 仕入先→愛知", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "1140", life: "48.8", url:"index.php?act=staff&id=1140", img:"user_data/7689.jpg", nen:"平成22年式", soukou:"84878", title:"ウィッシュ 1.8S ブラック766 仕入先→岡山", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "1130", life: "68.8", url:"index.php?act=staff&id=1130", img:"user_data/7694.jpg", nen:"平成24年式", soukou:"61393", title:"シャトルHV5605 スマートセレクション グレー 仕入先→岡山", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1129", life: "68.8", url:"index.php?act=staff&id=1129", img:"user_data/7713.jpg", nen:"平成23年式", soukou:"74738", title:"フィットシャトルHV5606 プレミアムセレクション 緑 仕入先→兵庫", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1128", life: "58.8", url:"index.php?act=staff&id=1128", img:"user_data/7681.jpg", nen:"平成24年式", soukou:"111977", title:"フィットシャトルHV5624 プレミアムセレクション 仕入先→兵庫", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1122", life: "58.8", url:"index.php?act=staff&id=1122", img:"user_data/7677.jpg", nen:"平成23年式", soukou:"98899", title:"フリードスパイク Gエアロ 銀5633仕入先→愛知", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1121", life: "58.8", url:"index.php?act=staff&id=1121", img:"user_data/7609.jpg", nen:"平成24年式", soukou:"111334", title:"フリード Gジャストセレクション シルバー5644 仕入先→福岡", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1119", life: "43.8", url:"index.php?act=staff&id=1119", img:"user_data/7675.jpg", nen:"平成22年式", soukou:"107296", title:"フリード FREXエアロ5640 紺 仕入先→東京", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1118", life: "43.8", url:"index.php?act=staff&id=1118", img:"user_data/7674.jpg", nen:"平成21年式", soukou:"114120", title:"フリード GエアロPKG5622 パール 仕入先→東京", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1109", life: "53.8", url:"index.php?act=staff&id=1109", img:"user_data/7596.jpg", nen:"平成05年式", soukou:"134,542", title:"テラノ4WD ニッサン グレー 仕入先→東京", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "1099", life: "63.8", url:"index.php?act=staff&id=1099", img:"user_data/7584.jpg", nen:"平成24年式", soukou:"102000", title:"フリードHVジャストセレクション青5547 仕入先→福岡", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "1095", life: "73.8", url:"index.php?act=staff&id=1095", img:"user_data/7570.jpg", nen:"平成24年式", soukou:"94452", title:"プリウスα G 7名乗 トヨタ 仕入先→愛知", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "1085", life: "118.8", url:"index.php?act=staff&id=1085", img:"user_data/7567.jpg", nen:"平成26年式", soukou:"73880", title:"ヴェゼルハイブリッドX青仕入→岐阜", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "1078", life: "168.8", url:"index.php?act=staff&id=1078", img:"user_data/7542.jpg", nen:"平成27年式", soukou:"71944", title:"エクストレイル756HVエマブレ20X 4WD仕入先→愛知", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "1061", life: "53.8", url:"index.php?act=staff&id=1061", img:"user_data/7344.jpg", nen:"平成23年式", soukou:"83613", title:"ジューク15RXガンメタ ニッサン 仕入先→沖縄", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "1038", life: "43.8", url:"index.php?act=staff&id=1038", img:"user_data/6965.jpg", nen:"平成23年式", soukou:"118866", title:"シャトルHV銀5447 ホンダ 仕入先→福岡", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1028", life: "43.8", url:"index.php?act=staff&id=1028", img:"user_data/6932.jpg", nen:"平成22年式", soukou:"81490", title:"フリードGエアロ黒5440 ホンダ 仕入先→沖縄", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "993", life: "33.8", url:"index.php?act=staff&id=993", img:"user_data/6930.jpg", nen:"平成23年式", soukou:"123300", title:"シャトル黒5441 ホンダ 仕入先→埼玉", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "964", life: "38.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: "957", life: "48.8", url:"index.php?act=staff&id=957", img:"user_data/6796.jpg", nen:"平成22年式", soukou:"95835", title:"ウイッシュ銀763 トヨタ 仕入先→福岡", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "930", life: "38.8", url:"index.php?act=staff&id=930", img:"user_data/6615.jpg", nen:"平成26年式", soukou:"110700", title:"シャトルHV銀5540 ホンダ 仕入先→神奈川", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "892", life: "63.8", url:"index.php?act=staff&id=892", img:"user_data/6370.jpg", nen:"平成25年式", soukou:"91002", title:"フィルダー銀5258 トヨタ 仕入先→神奈川", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "868", life: "58.8", url:"index.php?act=staff&id=868", img:"user_data/6227.jpg", nen:"平成26年式", soukou:"120765", title:"フィールダーHV水色5204 仕入先→福岡", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "854", life: "38.8", url:"index.php?act=staff&id=854", img:"user_data/5854.jpg", nen:"平成22年式", soukou:"96420", title:"プレマシーワイン682 マツダ 仕入先→埼玉", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "840", life: "43.8", url:"index.php?act=staff&id=840", img:"user_data/5841.jpg", nen:"平成23年式", soukou:"80466", title:"プレマシーワイン677 マツダ 仕入先→大阪", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "834", life: "48.8", url:"index.php?act=staff&id=834", img:"user_data/5785.jpg", nen:"平成24年式", soukou:"111834", title:"シャトル銀5135 ホンダ 仕入先→大阪", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "816", life: "43.8", url:"index.php?act=staff&id=816", img:"user_data/5655.jpg", nen:"平成23年式", soukou:"110813", title:"ラフェスタ白764 ニッサン", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "814", life: "38.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: "43.8", url:"index.php?act=staff&id=801", img:"user_data/5544.jpg", nen:"平成22年式", soukou:"91756", title:"ウイッシュ黒664 トヨタ", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "779", life: "38.8", url:"index.php?act=staff&id=779", img:"user_data/4939.jpg", nen:"平成22年式", soukou:"82484", title:"プレマシーワイン635 マツダ", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "775", life: "38.8", url:"index.php?act=staff&id=775", img:"user_data/4928.jpg", nen:"平成22年式", soukou:"97388", title:"プレマシーワイン633 マツダ", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "765", life: "48.8", url:"index.php?act=staff&id=765", img:"user_data/4917.jpg", nen:"平成22年式", soukou:"63870", title:"ウイッシュ銀4954 トヨタ", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "744", life: "38.8", url:"index.php?act=staff&id=744", img:"user_data/4898.jpg", nen:"平成23年式", soukou:"96118", title:"フリード銀5514ホンダ", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "431", life: "33.8", url:"index.php?act=staff&id=431", img:"user_data/2363.jpg", nen:"平成24年式", soukou:"118200", title:"フィットシャトルHV5485 ホンダ", 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(); });