Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/387.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 从SQL中删除_Javascript_Reactjs - Fatal编程技术网

Javascript 从SQL中删除

Javascript 从SQL中删除,javascript,reactjs,Javascript,Reactjs,我正在开发一个与SQL数据库通信的小型桌面应用程序。当我打开应用程序时,我会得到数据库中注册的所有学生的列表。当我点击一个特定的学生时,我会得到更多关于他们的信息,我可以编辑他们的信息。我还尝试添加一个删除按钮,但这就是我需要帮助的地方。代码如下所示: class Students1Details扩展组件{ student1=null 程序=[] render(){ 如果(!this.student1)返回null 返回( 姓名:{ this.student1.name=event.curr

我正在开发一个与SQL数据库通信的小型桌面应用程序。当我打开应用程序时,我会得到数据库中注册的所有学生的列表。当我点击一个特定的学生时,我会得到更多关于他们的信息,我可以编辑他们的信息。我还尝试添加一个删除按钮,但这就是我需要帮助的地方。代码如下所示:

class Students1Details扩展组件{
student1=null
程序=[]
render(){
如果(!this.student1)返回null
返回(
  • 姓名:{ this.student1.name=event.currentTarget.value;}>
  • 电邮:{ this.student1.email=event.currentTarget.value}>
  • 节目:{ this.program=event.currentTarget.value }}>
  • { studentService.updateStudent(this.student1,()=>{ Students1Details.instance().mounted() }) }}>更新 { studentService.deleteStudent(this.student1,()=>{}) }}>删除
) } 安装的(){ studentService.getStudent(this.props.match.params.id,(student1)=>{ this.student1=student1 studyProgramService.getStudyProgram(this.student1.studyProgramId,(program)=> (this.program=program.name)) studentService.deleteStudent(this.props.match.params.id,(student1)=>{ this.student1=student1 }) }) }
}
看起来您正在mounted()中调用deleteStudent。这可能是您的问题。

mounted()
方法中调用
studentService.deleteStudent()
。可能不应该这样做。那么,只有在单击按钮时,我如何调用它呢?似乎您已经在保存按钮的onClick处理程序中连接了它。我想你需要一个新的删除按钮来触发当前事件处理程序,而不是在保存时执行。是的,我的假设是,它只会在我单击按钮时运行,因为它是连接到的。但我一点击这个名字它就开始运行了。抱歉,我刚开始学习React,因此我不完全确定如何更改代码,使其仅在单击名称时运行OnClick,而不是在单击名称后立即运行如果您从mounted()中删除deleteStudent调用并检查按钮。。。。这个{{studentService.deleteStudion(This.student1,()=>{}}}>Save}将调用delete,即使按钮上显示SaveI修复了它!:)(按钮本应显示删除,但输入错误)。我从mounted中删除了它,并在外部创建了一个名为delete:delete(){studentService.deleteStuent(this.props.match.params.id,(student1)=>{this.student1=student1})的新函数,然后在按钮上执行以下操作:delete