问题描述
我的代码有两个错误,app.get 在 app.post 之前执行,我必须在将值存储在变量中之前在下拉列表中选择 2 个不同的值
nodejs:getBrandandManufacturer1 从医学数据库返回详细信息,其中品牌名称匹配并存储在数组中。 getBrandandManufacturer 将数组发送到前端
var testvar=[];
let getBrandandManufacturersql1 = `SELECT * FROM medicinedatabase where Brandname=? `;
app.post("/getBrandandManufacturer1",(req,res) => {
var jtBrandname = req.body.Brandname;
db.query(getBrandandManufacturersql1,[jtBrandname],(err,result) => {
if (err) {
console.log(err);
} else {
testvar.push(result)
//res.send(result)
console.log("getBrandandManufacturersql",testvar)
}
});
});
app.get("/getBrandandManufacturer",res) => {
res.send(testvar)
console.log("getBrandandManufacturersql2",testvar)
});
Reactjs :当值选择值时,查询在onchange
中执行 const [Brandname,setBrandname] = useState();
const [Manufacturer,setManufacturer] = useState();
const [brandnamemedicineList,setbrandnamemedicineList] = useState([])
const [manufacmedicineList,setmanufacmedicineList] = useState([])
<div className="addMed">
<div className ="inputcss">
<select className="inputfield" name="Brand Name" onChange={(event) => {
setBrandname(event.target.value);;
console.log("brandname",Brandname)
Axios.post('http://localhost:3001/getBrandandManufacturer1',{
Brandname: Brandname,}).then(() => {
console.log("Success!");
});
Axios.get('http://localhost:3001/getBrandandManufacturer').then((response) => {
setmanufacmedicineList(response.data);
console.log("Update",response)
});
}}>
{brandnamemedicineList.map((e,key) => {
return <option value={e.Brandname}>{e.Brandname}</option>;
})}
</select>
<select className="inputfield" name="Manufacturer" onChange={(event) => {setManufacturer(event.target.value);}}>
{manufacmedicineList.map((e,key) => {
return <option value={e.Manufacturer}>{e.Manufacturer}</option>;
})}
</select>
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)