var cups = [
{ type: 1, price: 100, color: 'black', sales: 60, name: '牛客logo马克杯' },
{ type: 2, price: 40, color: 'blue', sales: 100, name: '无盖星空杯' },
{ type: 4, price: 60, color: 'green', sales: 200, name: '老式茶杯' },
{ type: 3, price: 50, color: 'green', sales: 600, name: '欧式印花杯' }
]
var select = document.querySelector('select');
var ul = document.querySelector('ul');
// 补全代码
select.onchange = function(e){
const value = this..value;
let filterCups;
switch(value){
case '1':
filterCups = cups.filter(item=>item.sales < 100)
break;
case '2':
filterCups = cups.filter(item=>(item.sales <= 500) && (item.sales >= 100))
break;
case '3':
filterCups = cups.filter(item=>item.sales > 500)
default:
break;
}
let str = '';
filterCups.forEach(cup=>{
str += '<li>' + cup.name + '</li>'
})
ul.innerHTML = str;
}