正确使用 react-select-fast-filter-options 的方法
Correct way to use react-select-fast-filter-options
我正在使用 react-select-fast-filter-options 并在搜索任何内容时,即使在 select
标签中存在针对它的条目,我也没有得到任何结果。
我已经看到 问题,我面临一个非常相似的问题,但我没有将任何非默认 属性 传递给 react-virtualized-select
。
我的代码如下:
import "react-select/dist/react-select.css";
import React from "react";
import ReactDOM from "react-dom";
import createFilterOptions from "react-select-fast-filter-options";
import Select from "react-select";
import faker from "faker";
// Dummy array of test values.
const options = Array.from(new Array(100), (_, index) => ({
label: faker.lorem.sentence(),
value: index
}));
export default class SelectComponent extends React.Component {
render() {
console.log(this.props.alloptions);
return (
<Select
options={this.props.alloptions}
filterOptions={createFilterOptions(this.props.alloptions)}
/>
);
}
}
ReactDOM.render(
<SelectComponent alloptions={options} />,
document.getElementById("root")
);
我的猜测是 react-select-fast-filter-options
对我的数据进行索引是使用一些我不知道的隐藏字段完成的。
有什么我遗漏的吗?
当我将你问题中的代码放入 codesandbox 后,它可以正常工作。
https://codesandbox.io/s/vibrant-wind-rlp2i?fontsize=14&view=preview
我正在使用 react-select-fast-filter-options 并在搜索任何内容时,即使在 select
标签中存在针对它的条目,我也没有得到任何结果。
我已经看到 react-virtualized-select
。
我的代码如下:
import "react-select/dist/react-select.css";
import React from "react";
import ReactDOM from "react-dom";
import createFilterOptions from "react-select-fast-filter-options";
import Select from "react-select";
import faker from "faker";
// Dummy array of test values.
const options = Array.from(new Array(100), (_, index) => ({
label: faker.lorem.sentence(),
value: index
}));
export default class SelectComponent extends React.Component {
render() {
console.log(this.props.alloptions);
return (
<Select
options={this.props.alloptions}
filterOptions={createFilterOptions(this.props.alloptions)}
/>
);
}
}
ReactDOM.render(
<SelectComponent alloptions={options} />,
document.getElementById("root")
);
我的猜测是 react-select-fast-filter-options
对我的数据进行索引是使用一些我不知道的隐藏字段完成的。
有什么我遗漏的吗?
当我将你问题中的代码放入 codesandbox 后,它可以正常工作。
https://codesandbox.io/s/vibrant-wind-rlp2i?fontsize=14&view=preview