如何根据json数组过滤多反应选择数据



我有两个json文件,一个有症状列表,第二个文件有条件列表,其中有与条件匹配的症状json数组。我正试图找到一种方法,使用react-select来搜索条件json表中的症状数组,并只获取匹配的症状。随着我从反应选择中添加更多症状,出现的情况应该越来越少。我尝试了很多事情,但是运气不好。如有任何帮助,我们将不胜感激。

// condition_symptoms.js
export const condition_symptoms = [
{
condition: "Acetaminophen And Nsaid Toxicity",
symptions: ["Arm Pain", "Back Pain"],
},
{
condition: "Acne",
symptions: ["Leg Pain", "Back Pian", "Face Pain", "Arm Pain"],
},
{
condition: "Adrenal Disorders (Addison’S Disease And Cushing’S Syndrome",
symptions: ["Foot Pain", "Leg Pain", "Arm Pain"],
},
{
condition: "Age Related Cognitive Decline",
symptions: ["Jaw Pain", "Foot Pain", "Leg Pain", "Mouth Pain"],
},
export default condition_symptoms ;
// symptoms.js
export const symptoms = [
{ value: "leg pain", label: "Leg Pain" },
{ value: "arm Pain", label: "Arm Pain" },
{ value: "foot pain", label: "Foot Pain" },
{ value: "back pain", label: "Back Pain" },
]
// component.js
import symptomsConditions from "conditions_symptoms";
import symptoms from "symptoms";
function LandingPage() {
const onChange = (newValue) => {
console.log("onChange", newValue);
const condition = symptomsConditions.filter(symptom => {
symptom = Filter out condition here
} )
};
return {
<Select
onChange={onChange}
noOptionsMessage={() => "Please select a valid Symptom"}
placeholder="Please select symptoms"
options={symptoms}
size="large"
isMulti
isSearchable
/>
}
}

我还没有测试过,但类似的东西可能会起作用;

基本上,filterincludes函数应该为您提供一个起点。

var symptomsFound = symptoms.filter(function (s1) {
return !condition_symptoms.some(function (cs1) {
return cs1.symptions.includes(s1.value);
});
});

最新更新