【发布时间】:2019-07-24 12:28:59
【问题描述】:
我的返回函数在函数内部不起作用,请帮我解决这个问题。
import React from 'react';
import axios from 'axios';
const Category = () => {
//const[data, useData]=useState([]);
const FuncMen =() =>{
var e = document.getElementById("menid");
var country = e.options[e.selectedIndex].value;
if(country === "T-shirt"){
axios.post('http://localhost:8011/api/social/finddatamen',{country})
.then((res) => {
var men = res.data.res.filter(filtereddata => filtereddata.category === "tshirt" )
console.log('selected value is',men);
men &&men.map((val,i)=>{
console.log("Tshirtt:",val.Tshirt,"Price:",val.price);
return(
<div key={i}>
<h1>hello</h1>
{val.Tshirt},
{val.price}
</div>
)
})
})
.catch((error) => {
console.log('error block called',error);
})
}
【问题讨论】:
-
请给出解决方案
标签: node.js reactjs mongodb react-hooks