如果可以根据响应设置过滤条件,我可能会受到伤害。如果选择了“单选”按钮,则会从包含“单选按钮”的表单过滤数组。是否有一种更简单的方法可以解决这个问题,或者我是否更难以实现这一目标。
$(document).ready(function () {
$("#resultstest").clone("<tbody></tbody>");
$.ajax({
type: "GET",
url: "js/contacts.json",
dataType: "json",
cashe: false,
success: function (data) {
$("input[name=college-age]:radio").click(function () {
if ($('input[name=college-age]:checked').val() == "yes") {
var filterContacts = data.contacts.filter(function (contact) {
return contact.group.includes("College");
});
}
});
$("input[name=education]:radio").click(function () {
if ($('input[name=education]:checked').val() == "True") {
var filterContacts = data.contacts.filter(function (contact) {
return contact.group.includes("High School");
});
}
});
$("input[name=vet]:radio").click(function () {
if ($('input[name=vet]:checked').val() == "yes") {
var filterContacts = data.contacts.filter(function (contact) {
return contact.group.includes("Veterans");
});
}
});
$("input[name=housing]:radio").click(function () {
if ($('input[name=housing]:checked').val() == "yes") {
var filterContacts = data.contacts.filter(function (contact) {
return contact.group.includes("Homelessness");
});
}
});