// 選擇屋型處理 function change_type() { type = this.value; // 更新畫面資料 update_info(type, ping, budget, rooms); } // 選擇坪數處理 function change_ping() { ping = this.value; // 更新畫面資料 update_info(type, ping, budget, rooms); } // 選擇預算處理 function change_budget() { budget = this.value; // 更新畫面資料 update_info(type, ping, budget, rooms); } // 選擇格局處理 function change_rooms() { rooms = this.value; // 更新畫面資料 update_info(type, ping, budget, rooms); } // 更新畫面資料 function update_info(type, ping, budget, room) { console.log(type + ',' + ping + ',' + budget + ',' + room); // test (大樓,全部坪數,全部預算,全部格局) var items = []; // 作品集資料清單 // 讀取作品集資料(json) fetch('https://bhouse.ptt.cx/api/contents?url=/collection') .then(response => response.json()) .then(items => { console.log('讀取作品集資料(json)....'); var content = ""; console.log('載入符合篩選條件(' + type + ',' + ping + ',' + budget + ',' + rooms + ')的作品...........'); var filter_num = 0; // 篩選條件數量 if (!type.includes("全部")) { filter_num += 1; } if (!ping.includes("全部")) { filter_num += 1; } if (!budget.includes("全部")) { filter_num += 1; } if (!rooms.includes("全部")) { filter_num += 1; } console.log('篩選條件數: ' + filter_num); // test for(var i = 0; i < items.length; i++) { if (items[i]['url'] && items[i]['url'] != '/collection') { var tags = items[i]['tags'].replace('"', ''); // 各作品tag var matched_num = 0; // 符合篩選條件數量 if (tags.includes(type)) { matched_num += 1; } if (tags.includes(ping)) { matched_num += 1; } if (tags.includes(budget)) { matched_num += 1; } if (tags.includes(rooms)) { matched_num += 1; } console.log('符合篩選條件數: ' + matched_num); // test if (matched_num == 4) { content += ' \
' + items[i]['description'] + '
\