reactjs - 基于条件的 API 调用
问题描述
我有一个包含 2 个值(值 1 和值 2)的下拉列表,并且我有 2 个 API POST 调用。我有一个按钮。我想要的是选择值 1 如果选择了值 2,则对值 1 执行 POST 调用 对值 2 执行 API 发布并显示它们各自的结果。请指导我如何实现这一目标
我的帖子电话:
submit(){
const article = { model: this.state.model,
dataset:this.state.course,
path:this.state.checkbox };
axios.post('http://localhost:3000/home', article)
.then(response => this.setState({ s3path: response.data.s3_path , triton_output: response.data.triton_output, confidence: response.data.confidence,
inference_model:response.data.inference_model, loading: false,
}))
.catch(error => {
this.setState({ errorMessage: error.message });
console.error('There was an error!', error);
});
this.openModal();
this.state.loading=true
}
submit1(){
const article = { model: this.state.model,
dataset:this.state.course,
path:this.state.checkbox };
axios.post('http://localhost:3000/home', article)
.then(response => this.setState({ x: response.data.x , y: response.data.y_output, height: response.data.height,
inference_model:response.data.inference_model, loading: false,
}))
.catch(error => {
this.setState({ errorMessage: error.message });
console.error('There was an error!', error);
});
this.openModal();
this.state.loading=true
}
在这篇文章中,“Model:this.state.model”是选定的下拉值。我需要根据选定的下拉值调用 api
解决方案
我希望这段代码能解决你的问题;
var Test = React.createClass({
onClick: function(event){
if("Dropdown value check")
{
func1();
}
else{
func2();
}
},
render: function(){
return (
<a href="#" onClick={this.onClick}>Test Link</a>
);
}
});
推荐阅读
- asp.net - 带计时器的更新面板保持自动滚动页面
- php - SQL:如何通过关注者找到类似的博客
- openedge - 我想使用 match 以便它匹配在模式之间或单词开头有空格或空格的特定模式
- android - recyclerView (kotlin) 的一项中的 4 个可点击视图
- laravel - 如何在 Laravel 中保存 iframe 内容?
- html - 如何在图像上添加文本并添加段落将使用 html、css 在同一行开始
- reactjs - 将 Material-ui 图标放在圆形进度指示器内
- r - 如果 NULL 或满足条件,则在 R 中继续
- command-line - 选择第 3 行并显示第 3 行 TextFile BatchScript
- python - Python中使用Eratosthenes筛子的质数