API 根据条件调用
API Calls based on Condition
我有一个包含 2 个值(值 1 和值 2)的下拉列表,并且我有 2 个 API POST 调用。我有一个按钮。我想要的是选择值 1 如果选择值 2,则对值 1 执行 POST 调用 对值 2 执行 API post 并显示它们各自的结果。请指导我如何实现这个
我的 POST 通话:
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
}
在此 Post 中调用“模型: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>
);
}
});
我有一个包含 2 个值(值 1 和值 2)的下拉列表,并且我有 2 个 API POST 调用。我有一个按钮。我想要的是选择值 1 如果选择值 2,则对值 1 执行 POST 调用 对值 2 执行 API post 并显示它们各自的结果。请指导我如何实现这个
我的 POST 通话:
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
}
在此 Post 中调用“模型: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>
);
}
});