• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Rating
2
3提供在给定范围内选择评分的组件。
4
5>  **说明:**
6>
7>  该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
8
9
10## 子组件
11
1213
14
15## 接口
16
17Rating(options?: { rating: number, indicator?: boolean })
18
19**参数:**
20
21| 参数名 | 参数类型 | 必填 | 参数描述 |
22| -------- | -------- | -------- | -------- |
23| rating | number | 是 | 设置并接收评分值。<br/>默认值:0 |
24| indicator | boolean | 否 | 设置评分组件作为指示器使用,不可改变评分。<br/>默认值:false, 可进行评分 |
25
26
27## 属性
28
29| 名称 | 参数类型 | 描述 |
30| -------- | -------- | -------- |
31| stars | number | 设置评星总数。<br/>默认值:5 |
32| stepSize | number | 操作评级的步长。<br/>默认值:0.5 |
33| starStyle | {<br/>backgroundUri:&nbsp;string,<br/>foregroundUri:&nbsp;string,<br/>secondaryUri?:&nbsp;string<br/>} | backgroundUri:未选中的星级的图片链接,可由用户自定义或使用系统默认图片,仅支持本地图片。<br/>foregroundUri:选中的星级的图片路径,可由用户自定义或使用系统默认图片,仅支持本地图片。<br/>secondaryUir:部分选中的星级的图片路径,可由用户自定义或使用系统默认图片,仅支持本地图片。 |
34
35
36## 事件
37
38| 名称 | 功能描述 |
39| -------- | -------- |
40| onChange(callback:(value:&nbsp;number)&nbsp;=&gt;&nbsp;void) | 操作评分条的评星发生改变时触发该回调。 |
41
42
43## 示例
44
45```ts
46// xxx.ets
47@Entry
48@Component
49struct RatingExample {
50  @State rating: number = 1
51  @State indicator: boolean = false
52
53  build() {
54    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
55      Text('current score is ' + this.rating).fontSize(20)
56      Rating({ rating: this.rating, indicator: this.indicator })
57        .stars(5)
58        .stepSize(0.5)
59        .onChange((value: number) => {
60          this.rating = value
61        })
62    }.width(350).height(200).padding(35)
63  }
64}
65```
66
67![zh-cn_image_0000001219662659](figures/zh-cn_image_0000001219662659.gif)
68