如何从 onChange 事件中过滤 json 数组中的多个 json 项
How to filter multiple json items in a json array from onChange event
我有一个 react-select
组件,我正在从中获取多个值。然后我试图在 JSON 数组中找到所有匹配项。我一直在尝试一段时间无法找出最好的方法。我想过滤并打印匹配项。下面是数据。我想获取与所选症状匹配的所有条件。
export const symptomsCondition = [
{
condition: "Acetaminophen And Nsaid Toxicity",
symptions: ["Disorganized Speech", "Insomnia"],
},
{
condition: "Acne",
symptions: ["Swelling (Axilla)", "Bleeding Easily", "Difficult To Wake Up", "Increased Thirst"],
},
{
condition: "Adrenal Disorders (Addison’S Disease And Cushing’S Syndrome",
symptions: ["Weakness (Leg)", "Tremor", "Premature Ejaculation"],
},
{
condition: "Age Related Cognitive Decline",
symptions: ["Swelling (Jaw)", "Furry Tongue", "Headache (Worst Ever)", "Mucus In Eyes"],
},
{
condition: "Alcohol: Reducing The Risks",
symptions: [
"Pulling Out Eyebrows",
"Bleeding (Toes)",
"Craving To Eat Ice",
"Weakness (Shoulder)",
"Pounding Heart",
],
},
{
condition: "Allergies",
symptions: ["Thick Saliva", "Unable To Grip (Hands)", "Irregular Heartbeat"],
},
const [yoursymptoms, setYourSymptoms] = useState(null);
useEffect(() => {
symptomsCondition.symptoms.find((yoursymptoms) =>
console.log(yoursymptoms);
)
}, [yoursymptoms]);
onChange={setYourSymptoms}
您必须根据要求的条件在阵列上使用 filter
。类似于:
const allConditions = symptomsConditions.filter(c => c.symptions.includes(yoursymptoms))
如果你只需要条件,你可以用
链接它
.map(c => c.conditon)
我有一个 react-select
组件,我正在从中获取多个值。然后我试图在 JSON 数组中找到所有匹配项。我一直在尝试一段时间无法找出最好的方法。我想过滤并打印匹配项。下面是数据。我想获取与所选症状匹配的所有条件。
export const symptomsCondition = [
{
condition: "Acetaminophen And Nsaid Toxicity",
symptions: ["Disorganized Speech", "Insomnia"],
},
{
condition: "Acne",
symptions: ["Swelling (Axilla)", "Bleeding Easily", "Difficult To Wake Up", "Increased Thirst"],
},
{
condition: "Adrenal Disorders (Addison’S Disease And Cushing’S Syndrome",
symptions: ["Weakness (Leg)", "Tremor", "Premature Ejaculation"],
},
{
condition: "Age Related Cognitive Decline",
symptions: ["Swelling (Jaw)", "Furry Tongue", "Headache (Worst Ever)", "Mucus In Eyes"],
},
{
condition: "Alcohol: Reducing The Risks",
symptions: [
"Pulling Out Eyebrows",
"Bleeding (Toes)",
"Craving To Eat Ice",
"Weakness (Shoulder)",
"Pounding Heart",
],
},
{
condition: "Allergies",
symptions: ["Thick Saliva", "Unable To Grip (Hands)", "Irregular Heartbeat"],
},
const [yoursymptoms, setYourSymptoms] = useState(null);
useEffect(() => {
symptomsCondition.symptoms.find((yoursymptoms) =>
console.log(yoursymptoms);
)
}, [yoursymptoms]);
onChange={setYourSymptoms}
您必须根据要求的条件在阵列上使用 filter
。类似于:
const allConditions = symptomsConditions.filter(c => c.symptions.includes(yoursymptoms))
如果你只需要条件,你可以用
链接它.map(c => c.conditon)