mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-04 21:08:55 +08:00
feat: 评分组件 texts、colors 过滤非数字key, 如:$$id
This commit is contained in:
parent
0a170793ec
commit
4f9395fb3b
@ -112,7 +112,8 @@ export class Rating extends React.Component<RatingProps, any> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sortKeys(map: {[propName: number]: string}) {
|
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)
|
(a: number | string, b: number | string) => Number(a) - Number(b)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -137,10 +138,10 @@ export class Rating extends React.Component<RatingProps, any> {
|
|||||||
const showKey = keys.filter(item => Number(item) < value).length;
|
const showKey = keys.filter(item => Number(item) < value).length;
|
||||||
|
|
||||||
const showColor = keys[showKey] !== undefined && colors[keys[showKey]];
|
const showColor = keys[showKey] !== undefined && colors[keys[showKey]];
|
||||||
showColor &&
|
|
||||||
this.setState({
|
this.setState({
|
||||||
showColor
|
showColor: showColor || ''
|
||||||
});
|
});
|
||||||
} else if (colors && typeof colors === 'string') {
|
} else if (colors && typeof colors === 'string') {
|
||||||
this.setState({
|
this.setState({
|
||||||
showColor: colors
|
showColor: colors
|
||||||
@ -153,10 +154,10 @@ export class Rating extends React.Component<RatingProps, any> {
|
|||||||
const showText =
|
const showText =
|
||||||
keys[showKey] !== undefined &&
|
keys[showKey] !== undefined &&
|
||||||
texts[keys[showKey] as keyof typeof texts];
|
texts[keys[showKey] as keyof typeof texts];
|
||||||
showText &&
|
|
||||||
this.setState({
|
this.setState({
|
||||||
showText
|
showText: showText || ''
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user