Reputation: 27
the thing is i have a json file and a need to know how to filter my data result depending on the city that i want to show. i have already tried working with filter like this:
agadir_medicineList() {
return this.state.data.filter(data.city === "Agadir").map(medicine => (
<Medicine_list key={medicine.title} medicine={medicine} />
));
but it didn't work. this is my json file data:
]
{
title: "Dr. kareem",
city: "Inezgane",
speciality: "Généraliste",
tel: "tel:000000000",
},
{
title: "Dr. Ahmed",
city: "Agadir",
speciality: "Généraliste",
tel: "tel:000000000",
},
{
title: "Dr. Jack",
city: "Ait Melloul",
speciality: "Généraliste",
tel: "tel:000000000",
}
]
Upvotes: 0
Views: 171
Reputation: 6325
You were close! The filter method expects a callback function as first parameter. Your code should look like:
agadir_medicineList() {
return this.state.data.filter(data => data.city === "Agadir").map(medicine => (
<Medicine_list key={medicine.title} medicine={medicine} />
));
Upvotes: 1