1 回答
TA贡献1780条经验 获得超3个赞
您的主要问题是 。您正在将筛选器设置为 ARRAY。您希望它是具有特定键名的对象。var filter =[];
$(".go").click(function(){
const filter = {
username: $("#username").val(),
geo: $("#geo").val(),
week: $("#week").val(),
team: $("#team").val(),
};
const otherFilterFormat = Object.keys(filter).reduce((a, c) => {
a[c] = filter[c].reduce((x, y) => {
x[y] = y;
return x;
}, {});
return a;
}, {});
console.log(filter, otherFilterFormat);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="form-popup" id="filter" style="display: block;">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<select id="username" multiple=""><option selected="true" disabled="">Username</option><option>user1</option><option>user2</option><option>user3</option><option>user4</option></select>
<select id="geo" multiple=""><option selected="true" disabled="">Geo</option><option>chennai</option><option>covai</option><option>hydrabad</option><option>cochin</option><option>mumbai</option></select>
<select id="week" multiple=""><option selected="true" disabled="">Weeks</option><option>week1</option><option>week2</option><option>week3</option><option>week4</option></select>
<select id="team" multiple=""><option selected="true" disabled="">Teams</option><option>Java</option><option>Lamp</option><option>Oracle</option><option>Sales</option></select>
<button class="go">GO</button>
</div>
添加回答
举报