$(function() { /*================================================================ 情報 ================================================================*/ var allList = [ { id: "1693", life: "73.8", url:"index.php?act=staff&id=1693", img:"user_data/11173.jpg", nen:"平成26年式", soukou:"50021", title:"【レ単楽】ホンダN-WGN G A-PKG2708【価格改定】", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1699", life: "68.8", url:"index.php?act=staff&id=1699", img:"user_data/11104.jpg", nen:"平成26年式", soukou:"55719", title:"【レ単じ】ニッサンデイズ S茶2709【価格改定】", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1701", life: "68.8", url:"index.php?act=staff&id=1701", img:"user_data/11019.jpg", nen:"平成26年式", soukou:"45715", title:"【レ単じ】ニッサンデイズハイウェイスター赤2711", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1716", life: "68.8", url:"index.php?act=staff&id=1716", img:"user_data/10931.jpg", nen:"平成26年式", soukou:"67,536", title:"【レ単じ】ニッサンデイズ ハイウェイスター紫2727", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1717", life: "68.8", url:"index.php?act=staff&id=1717", img:"user_data/12454.jpg", nen:"平成25年式", soukou:"44156", title:"【レ単楽】ミツビシekワゴン紫2760【価格改定】", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1719", life: "68.8", url:"index.php?act=staff&id=1719", img:"user_data/10797.jpg", nen:"平成25年式", soukou:"47051", title:"【レ単楽】ミツビシekワゴンM2761【価格改定】", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1733", life: "98.8", url:"index.php?act=staff&id=1733", img:"user_data/10965.jpg", nen:"平成26年式", soukou:"64288", title:"【レ単楽】ホンダN-WGNカスタム G・Aパッケージ青 2729", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1736", life: "78.8", url:"index.php?act=staff&id=1736", img:"user_data/10796.jpg", nen:"平成25年式", soukou:"39517", title:"【レ単じ】ホンダN-ONE G・Lパッケージ白2725", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1738", life: "88.8", url:"index.php?act=staff&id=1738", img:"user_data/11038.jpg", nen:"平成29年式", soukou:"33238", title:"【レ単レ】ダイハツミライースL赤2758【価格改定】", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1746", life: "68.8", url:"index.php?act=staff&id=1746", img:"user_data/10802.jpg", nen:"平成25年式", soukou:"41921", title:"【レ単じ】ホンダN-ONE Gピンク2752【価格改定】", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1748", life: "98.8", url:"index.php?act=staff&id=1748", img:"user_data/10857.jpg", nen:"平成29年式", soukou:"74911", title:"【カ単喫】ワゴンRハイブリッドFX白2795", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1796", life: "78.8", url:"index.php?act=staff&id=1796", img:"user_data/11040.jpg", nen:"平成26年式", soukou:"51018", title:"【レDP楽】ニッサンデイズルークスX赤2913", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1802", life: "68.8", url:"index.php?act=staff&id=1802", img:"user_data/10944.jpg", nen:"平成27年式", soukou:"93773", title:"【ツ単楽】デイズルークスアンシャンテピンク2877", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1810", life: "63.8", url:"index.php?act=staff&id=1810", img:"user_data/11034.jpg", nen:"平成26年式", soukou:"36399", title:"【レ単じ】ニッサンデイズピンク2855【価格改定】", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1814", life: "54.8", url:"index.php?act=staff&id=1814", img:"user_data/10898.jpg", nen:"平成26年式", soukou:"87,000*", title:"【レ単じ】ニッサンデイズハイウェイスター黒2876", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1847", life: "68.8", url:"index.php?act=staff&id=1847", img:"user_data/11143.jpg", nen:"平成25年", soukou:"74890", title:"【レ単楽】ミツビシekワゴンGピンク2937", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1858", life: "73.8", url:"index.php?act=staff&id=1858", img:"user_data/10856.jpg", nen:"平成26年式", soukou:"17099", title:"【レ単じ】ニッサンデイズハイウェイスター紫2931", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1870", life: "73.8", url:"index.php?act=staff&id=1870", img:"user_data/11155.jpg", nen:"平成25年式", soukou:"38453", title:"【レ単じ】ニッサンデイズX2958【価格改定】", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1877", life: "78.8", url:"index.php?act=staff&id=1877", img:"user_data/10929.jpg", nen:"平成29年式", soukou:"96572", title:"【レ単じ】ホンダN-BOX G_SSパッケージ黒2954", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1895", life: "118.8", url:"index.php?act=staff&id=1895", img:"user_data/10990.jpg", nen:"平成28年式", soukou:"35433", title:"【ツ単レ】ハスラー黄色JスタイルⅡ3154", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "1913", life: "128.8", url:"index.php?act=staff&id=1913", img:"user_data/11008.jpg", nen:"平成30年式", soukou:"25517", title:"【レDP楽】デイズルークスボレロ茶3053", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "1918", life: "108.8", url:"index.php?act=staff&id=1918", img:"user_data/10999.jpg", nen:"平成29年式", soukou:"33681", title:"【ツ単レ】スズキハスラーG黄色3156", sold:"", new:"", tag: ["","","","AT","売り切れ"], description: "tesut" }, { id: "1919", life: "83.8", url:"index.php?act=staff&id=1919", img:"user_data/11014.jpg", nen:"平成27年式", soukou:"55863", title:"【レDP楽】ルークスX3135 Vセレクション+セーフティ2", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1923", life: "73.8", url:"index.php?act=staff&id=1923", img:"user_data/11174.jpg", nen:"平成26年式", soukou:"53327", title:"【レDP】ニッサンデイズルークスX茶3052", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1924", life: "128.8", url:"index.php?act=staff&id=1924", img:"user_data/11178.jpg", nen:"平成30年式", soukou:"49716", title:"【ツ単レ】スズキハスラーG黄色3054", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1926", life: "138.8", url:"index.php?act=staff&id=1926", img:"user_data/11016.jpg", nen:"令和2年式", soukou:"62,000", title:"【ツDPじ】スズキスペーシアHV Xアップグレードパッケージ", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1933", life: "128.8", url:"index.php?act=staff&id=1933", img:"user_data/11951.jpg", nen:"平成30年", soukou:"22839", title:"【レDP楽】ニッサンデイズルークスX茶3051", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1934", life: "148.8", url:"index.php?act=staff&id=1934", img:"user_data/11066.jpg", nen:"平成29年式", soukou:"8556", title:"【ツDP楽】ニッサンデイズルークスX3159", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1935", life: "148.8", url:"index.php?act=staff&id=1935", img:"user_data/11063.jpg", nen:"令和3年式", soukou:"4143", title:"【ツDPじ】スズキスペーシアG HVミント3056", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1936", life: "128.8", url:"index.php?act=staff&id=1936", img:"user_data/11064.jpg", nen:"平成29年式", soukou:"46944", title:"【ツDP楽】ニッサンデイズルークスX銀3130", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1938", life: "138.8", url:"index.php?act=staff&id=1938", img:"user_data/11202.jpg", nen:"平成30年式", soukou:"46560", title:"【ツDPじ】スペーシアG HVミント3067", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1939", life: "138.8", url:"index.php?act=staff&id=1939", img:"user_data/11181.jpg", nen:"平成31年式", soukou:"12810", title:"【ツDP楽】ニッサンデイズルークスX赤3064", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1940", life: "158.8", url:"index.php?act=staff&id=1940", img:"user_data/11184.jpg", nen:"令和3年式", soukou:"3773", title:"【ツ単楽】ニッサンデイズルークスX赤3066", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "1950", life: "88.8", url:"index.php?act=staff&id=1950", img:"user_data/11183.jpg", nen:"平成27年式", soukou:"35944", title:"【ツDP楽】ニッサンデイズルークスX紫3061", sold:"", new:"", tag: ["","","","AT","売り切れ"], description: "tesut" }, { id: "1951", life: "158.8", url:"index.php?act=staff&id=1951", img:"user_data/11081.jpg", nen:"令和3年式", soukou:"1916", title:"【ツ単楽】ニッサンルークスX HV パール", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "1956", life: "138.8", url:"index.php?act=staff&id=1956", img:"user_data/11193.jpg", nen:"令和1年式", soukou:"30,000", title:"【ツDP楽】ニッサンデイズルークスS シルバー", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1969", life: "98.8", url:"index.php?act=staff&id=1969", img:"user_data/11090.jpg", nen:"平成26年式", soukou:"51636", title:"【ツ単レ】スズキハスラーXターボ3153", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "1974", life: "138.8", url:"index.php?act=staff&id=1974", img:"user_data/11201.jpg", nen:"平成29年式", soukou:"25140", title:"【ツDPじ】スズキスペーシアG HV3134", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1975", life: "88.8", url:"index.php?act=staff&id=1975", img:"user_data/11187.jpg", nen:"平成27年式", soukou:"50761", title:"【ツ単楽】デイズルークスS銀3080", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1978", life: "128.8", url:"index.php?act=staff&id=1978", img:"user_data/11981.jpg", nen:"平成28年式", soukou:"56112", title:"【ツ単楽】ニッサンデイズルークスS銀3065", 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:"23405", title:"【ツDPじ】スズキスペーシアG HV3081", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1993", life: "98.8", url:"index.php?act=staff&id=1993", img:"user_data/11144.jpg", nen:"平成27年式", soukou:"59300", title:"【カ単喫】ホンダN-BOX G Lパッケージ3157", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1994", life: "98.8", url:"index.php?act=staff&id=1994", img:"user_data/11145.jpg", nen:"令和1年式", soukou:"45365", title:"【レ単じ】ニッサンデイズS銀3084", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1995", life: "88.8", url:"index.php?act=staff&id=1995", img:"user_data/11153.jpg", nen:"平成29年式", soukou:"25480", title:"【レ単楽】ekワゴンM_e-アシスト白3141", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "2009", life: "78.8", url:"index.php?act=staff&id=2009", img:"user_data/11176.jpg", nen:"平成29年式", soukou:"35995", title:"【レ単じ】ニッサンデイズS白3160", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1603", life: "68.8", url:"index.php?act=staff&id=1603", img:"user_data/10102.jpg", nen:"平成25年式", soukou:"59698", title:"【レ単じ】ホンダN-ONE Gピンク2591", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1568", life: "73.8", url:"index.php?act=staff&id=1568", img:"user_data/10061.jpg", nen:"平成26年式", soukou:"26648", title:"【レ単じ】ニッサンデイズS 銀2559【価格改定】", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1566", life: "68.8", url:"index.php?act=staff&id=1566", img:"user_data/10059.jpg", nen:"平成28年式", soukou:"42181", title:"【レ単楽】ミツビシekワゴンM 白2520【価格改定】", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1527", life: "68.8", url:"index.php?act=staff&id=1527", img:"user_data/10022.jpg", nen:"平成28年式", soukou:"70140", title:"【レ単レ】ダイハツムーブL SA Ⅱ 白2504", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1521", life: "69.8", url:"index.php?act=staff&id=1521", img:"user_data/10017.jpg", nen:"平成24年式", soukou:"63080", title:"【レ単じ】ホンダN-ONE Gピンク2466", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1517", life: "68.8", url:"index.php?act=staff&id=1517", img:"user_data/10014.jpg", nen:"平成26年式", soukou:"52726", title:"【レ単楽】ホンダN-WGN G A-PKG茶2561", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1514", life: "148.8", url:"index.php?act=staff&id=1514", img:"user_data/10035.jpg", nen:"令和3年式", soukou:"13257", title:"【レ単じ】ニッサンデイズX2464【価格改定】", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1513", life: "68.8", url:"index.php?act=staff&id=1513", img:"user_data/10012.jpg", nen:"平成25年式", soukou:"51147", title:"2⃣ホンダN-ONE G白2444【価格改定】", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1510", life: "98.8", url:"index.php?act=staff&id=1510", img:"user_data/10003.jpg", nen:"平成29年式", soukou:"35393", title:"【カ単喫】スズキワゴンR HV FX2366【価格改定】", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1504", life: "148.8", url:"index.php?act=staff&id=1504", img:"user_data/10008.jpg", nen:"令和3年式", soukou:"11128", title:"【レ単楽】ミツビシekスペースG2458【価格改定】", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1386", life: "148.8", url:"index.php?act=staff&id=1386", img:"user_data/9584.jpg", nen:"令和3年", soukou:"16235", title:"【レ単楽】ミツビシekワゴン2174", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1371", life: "58.8", url:"index.php?act=staff&id=1371", img:"user_data/9573.jpg", nen:"平成26年式", soukou:"69960", title:"【レ単楽】ミツビシekワゴンM白2386", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1359", life: "148.8", url:"index.php?act=staff&id=1359", img:"user_data/9428.jpg", nen:"令和3年式", soukou:"17114", title:"【レ単楽】ミツビシekワゴンM白2140【価格改定】", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1306", life: "118.8", url:"index.php?act=staff&id=1306", img:"user_data/9148.jpg", nen:"平成29年式", soukou:"35923", title:"【カ単喫】ダイハツタント銀2141X【価格改定】", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1297", life: "68.8", url:"index.php?act=staff&id=1297", img:"user_data/9099.jpg", nen:"平成27年式", soukou:"66236", title:"【レ単じ】デイズX/エマージェンシーブレーキレス2385", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "1287", life: "68.8", url:"index.php?act=staff&id=1287", img:"user_data/9005.jpg", nen:"平成26年式", soukou:"69399", title:"【レ単レ】ダイハツムーブカスタム2112【価格改定】", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "2059", life: "98.8", url:"index.php?act=staff&id=2059", img:"./img/nophoto.png", nen:"平成29年式", soukou:"33591", title:"【レ単楽】ホンダN-WGN 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(); });