[英]Is there any alternative for “Asyncselect” of “React” in “react-native”?
I am new to React-native and stuck in one issue as I am still exploring options in it.
我是 React-native 的新手,并且由于我仍在探索其中的选项而陷入了一个问题。 My current issue is, I need to display a searchable drop down where it will display top five items and its going to come from an api and with a search field on the top.
我当前的问题是,我需要显示一个可搜索的下拉列表,它将显示前五个项目,它将来自 api 并在顶部有一个搜索字段。 When user types the data in search field, the drop down will start searching it by calling a async api and get the data and display in same drop down.
当用户在搜索字段中键入数据时,下拉列表将通过调用异步 api 开始搜索它并获取数据并显示在同一下拉列表中。 Is it possible in react-native?
react-native 有可能吗? In react, it can be done using "react-select/async" package.
在反应中,可以使用“react-select/async”package 来完成。 Below is the react code: React:
下面是反应代码: 反应:
async getOptions(inputValue, callback) {
if (!inputValue) {
return callback([]);
}
const response = await fetch(
`${this.state... }?search=${inputValue}&limit=${
this.state...
}`
);
const json = await response.json();
return callback(json.results);
}
<AsyncSelect
cacheOptions
defaultOptions
value={selectedValue}
getOptionLabel={e => e.title}
getOptionValue={e => e.id}
loadOptions={getOptions}
onInputChange={handleInputChange}
onChange={handleChange}
/>
There is a loadOptions param which is a callback function and it returns the data by calling async function.有一个 loadOptions 参数,它是一个回调 function,它通过调用异步 function 返回数据。
Can we do the same in react-native or which alternative we can use.?我们可以在 react-native 中做同样的事情,或者我们可以使用哪个替代方案。?
I am new to react-native any help would be really appreciated.我是 react-native 的新手,任何帮助将不胜感激。
Thanks in Advance.提前致谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.