文档开发者中心
我的
|

UI

DataPanel 组件的 contentModifier 属性,具体该如何使用?没搞明白

已解决

DataPanel 组件的 contentModifier 属性,具体该如何使用?没搞明白

cke_142.png

点赞
收藏
回复
4
分享
举报
浏览285 发布于2024-08-17 11:42北京
全部评论
最多点赞
最新发布
最早发布
|
采纳答复

modifier: 内容修改器,开发者需要自定义class实现ContentModifier接口。

  1. class DataPanelBuilder implements ContentModifier<DataPanelConfiguration> {
  2. constructor() {
  3. }
  4. applyContent () : WrappedBuilder<[DataPanelConfiguration]> {
  5. return wrapBuilder(buildDataPanel)
  6. }
  7. }
  8. @Entry
  9. @Component
  10. struct Index {
  11. build() {
  12. Column() {
  13. Text("Data panel").margin({ top: 12 });
  14. Row() {
  15. DataPanel({ values: [12.3, 21.1, 13.4, 35.2, 26.0, 32.0], max: 140, type: DataPanelType.Circle })
  16. .width(400).height(260)
  17. .padding({ top: 10 })
  18. .contentModifier(new DataPanelBuilder())
  19. }.margin(15).backgroundColor("#fff5f5f5")
  20. }
  21. }
  22. }
3
1楼回复于2024-08-17 15:44 来自浙江
  • Jelly
    就是卡在你回答的步骤, 具体下面方法里面,返回的部分怎么实现 applyContent () : WrappedBuilder<[DataPanelConfiguration]> { return wrapBuilder(buildDataPanel) }
    2024-08-18 02:46 来自北京
  • 阿福回复Jelly
    // xxx.ets @Builder function buildDataPanel(config: DataPanelConfiguration) { Column() { Column() { ForEach(config.values, (item: number, index: number) => { ChildItem({ item: item, index: index, max:config.maxValue}) }, (item: string) => item) }.padding(10) Line().width(360).backgroundColor("#ff373737").margin({bottom:5}) Row() { Text('Length=' + config.values.length + ' ').margin({ left: 10 }).align(Alignment.Start) Text('Max=' + config.maxValue).margin({ left: 10 }).align(Alignment.Start) } } } class DataPanelBuilder implements ContentModifier<DataPanelConfiguration> { constructor() { } applyContent () : WrappedBuilder<[DataPanelConfiguration]> { return wrapBuilder(buildDataPanel) } } @Entry @Component struct Index { build() { Column() { Text("Data panel").margin({ top: 12 }); Row() { DataPanel({ values: [12.3, 21.1, 13.4, 35.2, 26.0, 32.0], max: 140, type: DataPanelType.Circle }) .width(400).height(260) .padding({ top: 10 }) .contentModifier(new DataPanelBuilder()) }.margin(15).backgroundColor("#fff5f5f5") } } } @Component struct ChildItem { @Prop item: number; @Prop index: number; @Prop max: number; public color1: string = "#65ff00dd" public color2: string = "#6500ff99" public color3: string = "#65ffe600" public color4: string = "#6595ff00" public color5: string = "#65000dff" public color6: string = "#650099ff" public colorArray: Array<string> = [this.color1, this.color2, this.color3, this.color4, this.color5, this.color6] build() { RelativeContainer() { Row() { Rect().height(25).width(this.item * 600 / this.max).foregroundColor(this.colorArray[this.index]).radius(5) .align(Alignment.Start) Text(" "+this.item) .fontSize(17) } }.height(28) } }
    展开全部
    2024-08-18 04:32 来自浙江
  • 阿福回复Jelly
写回答
新增插入模板功能
一键使用模板,快速填写内容,轻松发帖~
知道了
  • 为了保障您的信息安全,请勿上传您的敏感个人信息(如您的密码等信息)和您的敏感资产信息(如关键源代码、签名私钥、调试安装包、业务日志等信息),且您需自行承担由此产生的信息泄露等安全风险。
  • 如您发布的内容为转载内容,请注明内容来源。

我要提问题

了解社区公约,与您携手共创和谐专业的开发者社区。