From 4f9395fb3bad9da7ab4c736ab5f789c94fa9d97a Mon Sep 17 00:00:00 2001 From: liuzedong02 Date: Fri, 15 Apr 2022 16:33:17 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=AF=84=E5=88=86=E7=BB=84=E4=BB=B6=20?= =?UTF-8?q?texts=E3=80=81colors=20=E8=BF=87=E6=BB=A4=E9=9D=9E=E6=95=B0?= =?UTF-8?q?=E5=AD=97key=EF=BC=8C=20=E5=A6=82=EF=BC=9A$$id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Rating.tsx | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/components/Rating.tsx b/src/components/Rating.tsx index 53fb0c4a6..95954d3c6 100644 --- a/src/components/Rating.tsx +++ b/src/components/Rating.tsx @@ -112,7 +112,8 @@ export class Rating extends React.Component { } sortKeys(map: {[propName: number]: string}) { - return Object.keys(map).sort( + // 需验证 key 是否是数字,需要过滤掉非数字key,如 $$id + return Object.keys(map).filter(item => !isNaN(Number(item))).sort( (a: number | string, b: number | string) => Number(a) - Number(b) ); } @@ -137,10 +138,10 @@ export class Rating extends React.Component { const showKey = keys.filter(item => Number(item) < value).length; const showColor = keys[showKey] !== undefined && colors[keys[showKey]]; - showColor && - this.setState({ - showColor - }); + + this.setState({ + showColor: showColor || '' + }); } else if (colors && typeof colors === 'string') { this.setState({ showColor: colors @@ -153,10 +154,10 @@ export class Rating extends React.Component { const showText = keys[showKey] !== undefined && texts[keys[showKey] as keyof typeof texts]; - showText && - this.setState({ - showText - }); + + this.setState({ + showText: showText || '' + }); } }