如何解决在这段代码中,为什么在发布之前执行,为什么我必须在下拉列表中选择 2 个值,然后才能将其存储在变量中?
我的代码有两个错误,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 举报,一经查实,本站将立刻删除。