The usage scenario of the AsyncPicker component is similar to a Picker with multiple levels of interdependence, which is designed to solve situations where lower level data is queried from the server based on upper level data selection. For example, after selecting data at the provincial level, corresponding data at the city level is queried dynamically, and then, after selecting city-level data, corresponding data at the district level is queried dynamically, and so on.
Using the AsyncPicker component requires more steps than a Picker with multiple levels of interdependence, because the data is not passed in at once but rather obtained dynamically through an API, so developers need to handle the data themselves.
By listening to the next and prev methods, update the new data "data" for the current column and dynamically bind it to the component's internal state. At the same time, you also need to dynamically bind whether the current column is the first level "lastLevel" and whether it is the last level "firstLevel".
When the data is at the last level, clicking on the right button triggers the confirm method and returns the selected data. When the data is not at the last level, clicking on the right button triggers the next method and returns the index value of the current selection.
The AsyncPicker component ultimately returns two pieces of data: an array "items" composed of multiple selected data columns, and another array "indexs" composed of the indexes of the multiple selected data columns. Use as needed.
The data structure of each item in "items" is the same as the data structure passed in, which is convenient for developers to use directly.
In actual development, the data of most AsyncPicker components is dynamically acquired, usually through an API. Normally, we need to loop through the passed-in data to make sure the AsyncPicker component can be used correctly. However, this is a somewhat cumbersome and unnecessary process, so STDF has optimized the input of the AsyncPicker component, allowing developers to directly pass in data returned by an API without needing to do looping themselves.
The AsyncPicker is wrapped based on Popup by defining some Popup Props in advance, so you can achieve different effects by passing in Popup properties. For example, in the example, we change the rounded corner style by setting the radius of the popup.
The loading displayed when data is loaded in AsyncPicker is wrapped based on Loading, so you can achieve different effects by passing in Loading properties. For example, in the example, we changed the loading effect by setting some parameters of the loading.
Radio, Checkbox, ActionSheet, IndexBar, Picker, and AsyncPicker components all essentially provide a series of data for users to select or perform certain operations, but they differ in usage: