24jieqi / react-native-xiaoshu

🌈 React Native UI library
https://24jieqi.github.io/react-native-xiaoshu/
Apache License 2.0
216 stars 21 forks source link

Selector onSearch的数据可以支持异步请求吗 #51

Open zl612 opened 8 months ago

zl612 commented 8 months ago

Selector({ title: '地址微调', options: addressList, search: true, placeholder: '搜索附近定位地点', onSearch: async(keyword: string, options) => { const res = await fetchNearbyLocations(keyword) return res } })

目前支持同步数据返回,返回的数据也有问题 需要单独处理 labels: { text: string highlight: boolean } 这个也比较麻烦

zl612 commented 8 months ago

或者搜索 请求回来的数据 放入options 中展示

zl612 commented 8 months ago

目前不支持远程请求数据吗

onlyling commented 8 months ago

Selector 内部用 Tree 组件实现列表、搜索,目前只支持同步返回新列表数据。

zl612 commented 8 months ago

行 我自己封装一个

zl612 commented 8 months ago

简单封装 欢迎优化

zl612 commented 8 months ago

`interface SearchCardProps { options: TreeOption[] onSearch: (Keywords:string) => void defaultValue?: Array<number|string> title?: string placeholder?: string visible: boolean setVisible: (visible: boolean) => void onChange: (v: TreeValue | TreeValue[], option: TreeOption[]) => void, editable?: boolean }

export type TreeValue = number | string

export default function SearchCard(props: SearchCardProps) { const { options, onSearch, defaultValue=[], title='', placeholder='', visible, setVisible, onChange, editable=true, } = props

return (

{ setVisible(false) }} /> { onSearch(v) }} /> ) }`
onlyling commented 8 months ago

关于「搜索关键词结果来自异步回调(接口响应)」感觉和当前设计有点冲突。

基于 Tree 组件做的组件,搜索的作用是过滤已给的 options 数组,如果完全放开,可能会混入一些非 options 内的数据,回显选中、增加减少的时候可能会存在逻辑冲突,有些别扭。

需要先确定是否需要放开候选项(可以随意添加非预设候选项),如果能放开,onSearch 回调就需要支持异步回调。

zl612 commented 8 months ago

因为需求调用的是高德地图 请求周围数据的接口 接口数据一次只返回20条 如需查询地点名称就得加入条件查询出来