Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 单击按钮时出现类型错误,说明函数未定义?_Javascript_Reactjs_Api_Typeerror_Eventhandler - Fatal编程技术网

Javascript 单击按钮时出现类型错误,说明函数未定义?

Javascript 单击按钮时出现类型错误,说明函数未定义?,javascript,reactjs,api,typeerror,eventhandler,Javascript,Reactjs,Api,Typeerror,Eventhandler,单击按钮时,我收到一个类型错误,说明函数未定义 putToDb = (message) => { console.log("rahul"); let currentIds = this.state.data.map((data)=>data.id); let idToBeAdded = 0; while(currentIds.includes(idToBeAdded)){ ++idToBeAdded; } axios.post('h

单击按钮时,我收到一个
类型错误
,说明函数未定义

putToDb = (message) => {
   console.log("rahul");
   let currentIds = this.state.data.map((data)=>data.id);
   let idToBeAdded = 0;
   while(currentIds.includes(idToBeAdded)){
       ++idToBeAdded;
   }

   axios.post('http://localhost:3001/api/putData',{
       id:idToBeAdded,
      message:message,
  })
};
当我运行前端服务器并单击“添加”按钮时,浏览器显示未定义函数
putToDB

putToDb = (message) => {
   console.log("rahul");
   let currentIds = this.state.data.map((data)=>data.id);
   let idToBeAdded = 0;
   while(currentIds.includes(idToBeAdded)){
       ++idToBeAdded;
   }

   axios.post('http://localhost:3001/api/putData',{
       id:idToBeAdded,
      message:message,
  })
};
在渲染部分

<div style={{ padding: '50px' }}>
<input type="text"
  onChange={(e) => this.setState({ message: e.target.value })}
  placeholder="add something in the database"
  style={{ width: '200px' }}
/>
<button onClick={() => this.putToDB(this.state.message)}>
   ADD
</button>enter code here
</div>

this.setState({message:e.target.value})}
占位符=“在数据库中添加内容”
样式={{width:'200px'}}
/>
this.putToDB(this.state.message)}>
添加
在这里输入代码

这是因为当您试图调用结尾为大写字母“b”的函数时,“puttob”中的“b”是小写的


以后,请上传整个组件结构并格式化代码。

请共享整个组件代码。目前还不清楚你试过什么。