有什么方法可以用您记下的值更新数据库中的记录?

时间:2020-02-08 16:40:11

标签: javascript node.js reactjs mongodb axios

我有自动搜索字段,可让您查找员工或仅写下其姓名。我添加了一个按钮,该按钮会将员工分配到机器上,并在那里请求PUT。出现了一个问题:如何用手写字母的值更新记录?它比发送更新的切换要难一些;-;

 const ConfirmButton = props => {
 const [role, setRole] = useState("");
 const [autosearchValue, setAutosearchValue] = useState(props.autosearchValue);
 const [bnsName, setBnsName] = useState(props.bnsName);
 // unimportant const
 const [userInput, setUserInput] = "";

 // authorization check + role check

   const assignEmployee = () => {
     if (checkRole(role)) {
       axios
         .put(http://localhost:5000/api/bns/ + bnsName, {
           headers: {
             Accept: "application/json",
             "Content-Type": "application/json"
           },
           autosearchValue: userInput
         })

         .then(response => {
           console.log(response);
              })

         .catch(error => {
           console.log(error);
         })
     }
   };

  const logged = (
       <div className="" style={{ width: "100%" }}>
   <button className="confirmbutton" onClick={() => assignEmployee()}><span className="confirmspan">+                    
 </span></button>
 </div>
  );

这是它的样子: enter image description here

0 个答案:

没有答案