【发布时间】:2020-11-16 22:01:39
【问题描述】:
我有一个项目,在项目中有一年的组合框。我将年份排序(asc to desc 或 desc to asc)。
我有一个表单 utils,我在组件中调用了 utils。
【问题讨论】:
-
在您提供有关您的问题的足够信息之前,没有人可以帮助您。至少你可以包含你正在使用的代码。
标签: reactjs typescript react-native
我有一个项目,在项目中有一年的组合框。我将年份排序(asc to desc 或 desc to asc)。
我有一个表单 utils,我在组件中调用了 utils。
【问题讨论】:
标签: reactjs typescript react-native
试试这个方法
import React, { Component } from "react";
import Select from "react-select";
function compare(a, b) {
return a.label > b.label ? 1 : b.label > a.label ? -1 : 0;
}
class App extends Component {
constructor(props) {
super(props);
this.state = {
options: [
{
label: 1940,
value: 1
},
{
label: 1945,
value: 2
},
{
label: 1942,
value: 3
},
{
label: 1941,
value: 4
},
{
label: 1946,
value: 5
}
]
};
}
render() {
return (
<Select
//isMulti
hideSelectedOptions={false}
options={this.state.options.sort(compare)}
/>
);
}
}
【讨论】: