前端:
const [searchParameters, setSearchParameters] = useState({
type: "",
country:"",
});
const onChangeSearchType = e => {
const workingObject = {...searchParameters};
workingObject.searchType = e.target.value;
setSearchParameters(workingObject);
};
const onChangeSearchCountry = e => {
const workingObject = {...searchParameters};
workingObject.searchCountry = e.target.value;
setSearchParameters(workingObject);
};
const handleFetchWithSearchParameters = () => {
TutorialDataService.findByParameters(searchParameters)
.then(response => {
setTutorials(response.data);
console.log(response.data);
})
.catch(e => {
console.log(e);
});
}
之后return():
<Form.Control as="select" defaultValue=""
type="text"
className="form-control"
id="country"
required
value={searchParameters.country}
onChange={onChangeSearchCountry}
name="country">
<option>Nigeria</option>
<option>Ghana</option>
<option>Kenya</option>
<option>Senegal</option>
</Form.Control>
<Form.Control as="select" defaultValue=""
type="text"
className="form-control"
id="type"
required
value={searchParameters.type}
onChange={onChangeSearchType}
name="type">
<option>Agricultural</option>
<option>Manufacturing</option>
<option>Industrial</option>
<option>Livestock</option>
<option>Service Industry</option>
</Form.Control>
<div className="input-group-append">
<button
className="btn btn-outline-secondary"
type="button"
onClick={handleFetchWithSearchParameters}
Search
</button>
胡子哥哥
相关分类