Home > Web Front-end > Front-end Q&A > How to implement search by conditions in react

How to implement search by conditions in react

藏色散人
Release: 2022-12-28 16:08:30
Original
2243 people have browsed it

React method to implement search by conditions: 1. Define an object in the state; 2. Set the drop-down box click event onChange to receive the corresponding ID for each drop-down box selected; 3. The object can be attached to the interface request parameters.

How to implement search by conditions in react

The operating environment of this tutorial: Windows 10 system, react18.0.0 version, Dell G3 computer.

How to implement search by conditions in react?

react design pro implements multi-condition query data

1. Description:

For the backend management system, when writing the business interface, Joint querying data with multiple conditions is the most basic business requirement. Generally, multi-condition queries pass in the ID or other values ​​of the corresponding fields.

2. Implemented interface effect:

3. Implementation idea:

First define an object to receive the corresponding response for each selected drop-down box. Save the ID, and then finally attach the object to the interface request parameter.

For example: The data format required by my query interface here

{ merchantId: "", page: 1, limit: 15, departDate: "", lineId: "", driverId: "", carId: "" }
Copy after login

4. Code implementation:

1. First define an object in the state:

2. Set the drop-down box click event onChange

3. Assign value (only the code of the supplier drop-down box is shown here, other drop-down boxes The box is the same as the one):

How to implement search by conditions in react

#Finally, obtain the corresponding results and perform the corresponding query, and a multi-condition query is implemented.

5. Summary

Here I use setState to dynamically assign values ​​to object elements. This is the only way I can think of at the moment. I don’t know if there is a better way. If I hope someone can teach me.

Recommended learning: "react video tutorial"

The above is the detailed content of How to implement search by conditions in react. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template