$(function() { /*================================================================ 情報 ================================================================*/ var allList = [ { 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: "980", life: "69.8", url:"index.php?act=staff&id=980", img:"user_data/6902.jpg", nen:"平成26年式", soukou:"92861", title:"ハイゼットトラック白 ダイハツ 仕入先→神戸", sold:"", new:"", tag: ["新着","","","AT","売り切れ"], description: "tesut" }, { id: "981", life: "69.8", url:"index.php?act=staff&id=981", img:"user_data/6903.jpg", nen:"平成25年式", soukou:"117293", title:"スクラムワゴン銀1855 マツダ 仕入先→福岡", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "982", life: "39.8", url:"index.php?act=staff&id=982", img:"user_data/6894.jpg", nen:"平成21年式", soukou:"62000", title:"クリッパーバン白367ニッサン 仕入先→沖縄", sold:"", new:"", tag: ["","販売中","MT","",""], description: "tesut" }, { id: "948", life: "109.8", url:"index.php?act=staff&id=948", img:"user_data/6739.jpg", nen:"平成29年式", soukou:"71957", title:"ハスラー緑 スズキ 仕入先→沖縄", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "946", life: "82.8", url:"index.php?act=staff&id=946", img:"user_data/6795.jpg", nen:"平成26年式", soukou:"84533", title:"N-BOX銀 ホンダ 仕入先→神奈川", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "934", life: "71.8", url:"index.php?act=staff&id=934", img:"user_data/6601.jpg", nen:"平成26年式", soukou:"54801", title:"デイズピンク ニッサン 仕入先→沖縄", 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: "900", life: "72.8", url:"index.php?act=staff&id=900", img:"user_data/6380.jpg", nen:"平成25年式", soukou:"83343", title:"N-BOX銀1821 ホンダ 仕入先→神奈川", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "899", life: "49.8", url:"index.php?act=staff&id=899", img:"user_data/6378.jpg", nen:"平成26年式", soukou:"92301", title:"ハイゼットカーゴ白386 ダイハツ 仕入先→沖縄", sold:"", new:"", tag: ["","","","AT","売り切れ"], description: "tesut" }, { id: "871", life: "63.8", url:"index.php?act=staff&id=871", img:"user_data/6251.jpg", nen:"平成26年式", soukou:"106000", title:"Nワゴン銀1822 ホンダ 仕入先→沖縄", sold:"", new:"", tag: ["","","","AT","売り切れ"], description: "tesut" }, { id: "861", life: "54.8", url:"index.php?act=staff&id=861", img:"user_data/5986.jpg", nen:"平成26年式", soukou:"96340", title:"デイズ白1798 ニッサン 仕入先→沖縄", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "793", life: "39.8", url:"index.php?act=staff&id=793", img:"user_data/5533.jpg", nen:"平成22年式", soukou:"92217", title:"ラパンLブルー1705 スズキ", sold:"", new:"", tag: ["","","","AT","売り切れ"], description: "tesut" }, { id: "784", life: "44.8", url:"index.php?act=staff&id=784", img:"user_data/4927.jpg", nen:"平成24年式", soukou:"110019", title:"タントエグゼ茶1672ダイハツ", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "662", life: "42.8", url:"index.php?act=staff&id=662", img:"user_data/4478.jpg", nen:"平成21年式", soukou:"31130", title:"サンバーT銀338 スバル", sold:"", new:"", tag: ["","販売中","MT","",""], description: "tesut" }, { id: "629", life: "24.8", url:"index.php?act=staff&id=629", img:"user_data/4398.jpg", nen:"平成17年式", soukou:"109234", title:"クリッパーバン白333ニッサン", sold:"", new:"", tag: ["新着","販売中","MT","",""], description: "tesut" }, { id: "626", life: "34.8", url:"index.php?act=staff&id=626", img:"user_data/4389.jpg", nen:"平成22年式", soukou:"107263", title:"タントエグゼ黒1577ダイハツ", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "622", life: "39.8", url:"index.php?act=staff&id=622", img:"user_data/4375.jpg", nen:"平成26年式", soukou:"55463", title:"ムーブコンテ紫1631ダイハツ", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "617", life: "67.8", url:"index.php?act=staff&id=617", img:"user_data/4225.jpg", nen:"平成25年式", soukou:"103934", title:"N-ONE白1562 ホンダ", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "616", life: "42.8", url:"index.php?act=staff&id=616", img:"user_data/4207.jpg", nen:"平成23年式", soukou:"107194", title:"MRワゴン茶1561 スズキ", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "595", life: "44.8", url:"index.php?act=staff&id=595", img:"user_data/3951.jpg", nen:"平成25年式", soukou:"112254", title:"ハイゼット白303 ダイハツ", sold:"", new:"", tag: ["新着","販売中","MT","",""], description: "tesut" }, { id: "556", life: "49.8", url:"index.php?act=staff&id=556", img:"user_data/3694.jpg", nen:"平成24年式", soukou:"106395", title:"モコベージュ1486 ニッサン", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "500", life: "24.8", url:"index.php?act=staff&id=500", img:"user_data/3029.jpg", nen:"平成21年式", soukou:"117985", title:"ムーブコンテ1417 ダイハツ", sold:"", new:"", tag: ["","","","AT","売り切れ"], description: "tesut" }, { id: "496", life: "39.8", url:"index.php?act=staff&id=496", img:"user_data/3039.jpg", nen:"平成23年式", soukou:"114891", title:"ラパンピンク1399 スズキ", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "392", life: "19.8", url:"index.php?act=staff&id=392", img:"user_data/2271.jpg", nen:"平成17年式", soukou:"130256", title:"サンバートラック白284スバル", sold:"", new:"", tag: ["新着","","MT","","売り切れ"], description: "tesut" }, { id: "359", life: "49.8", url:"index.php?act=staff&id=359", img:"user_data/2108.jpg", nen:"平成24年式", soukou:"103394", title:"モコ白1347 ニッサン", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "985", life: "59.8", url:"index.php?act=staff&id=985", img:"./img/nophoto.png", nen:"平成26年式", soukou:"86127", title:"ミニキャブバン青 ミツビシ 仕入先→神奈川", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "988", life: "49.8", url:"index.php?act=staff&id=988", img:"./img/nophoto.png", nen:"平成20年式", soukou:"96000", title:"サンバートラックPRO4WD 白仕入先→岐阜", sold:"", new:"", tag: ["新着","販売中","MT","",""], description: "tesut" }, { id: "989", life: "59.8", url:"index.php?act=staff&id=989", img:"./img/nophoto.png", nen:"平成25年式", soukou:"96000", title:"ハイゼットトラックスペシャル4WD白 仕入先→岐阜", sold:"", new:"", tag: ["新着","販売中","MT","",""], description: "tesut" }, { id: "1003", life: "75.8", url:"index.php?act=staff&id=1003", img:"./img/nophoto.png", nen:"平成25年式", soukou:"83098", title:"⑭N BOX Gシルバー仕入先:神奈川", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "1029", life: "66.8", url:"index.php?act=staff&id=1029", img:"./img/nophoto.png", nen:"平成26年式", soukou:"39000", title:"㊵デイズ X ムラサキ仕入先:沖縄", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "1030", life: "59.8", url:"index.php?act=staff&id=1030", img:"./img/nophoto.png", nen:"平成19年式", soukou:"93000", title:"㊶キャリートラック4WD ホワイト仕入先:沖縄", sold:"", new:"", tag: ["新着","販売中","MT","",""], description: "tesut" }, { id: "1031", life: "59.8", url:"index.php?act=staff&id=1031", img:"./img/nophoto.png", nen:"平成25年式", soukou:"94000", title:"㊷ハイゼットバン ハイルーフ白仕入先:沖縄", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "1032", life: "59.8", url:"index.php?act=staff&id=1032", img:"./img/nophoto.png", nen:"平成25年式", soukou:"85000", title:"㊸ダイハツムーブ ホワイト仕入先:沖縄", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "1033", life: "49.8", url:"index.php?act=staff&id=1033", img:"./img/nophoto.png", nen:"平成21年式", soukou:"103000", title:"㊹タントカスタム X ブラック仕入先:沖縄", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "1034", life: "72.8", url:"index.php?act=staff&id=1034", img:"./img/nophoto.png", nen:"平成23年式", soukou:"67000", title:"㊺タントカスタム Xホワイト仕入先:沖縄", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "1036", life: "89.8", url:"index.php?act=staff&id=1036", img:"./img/nophoto.png", nen:"平成25年式", soukou:"58000", title:"㊼スペーシア X ピンク仕入先:沖縄", 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(); });