Jelly|
UI
DataPanel 组件的 contentModifier 属性,具体该如何使用?没搞明白
已解决
DataPanel 组件的 contentModifier 属性,具体该如何使用?没搞明白

4
浏览285 发布于2024-08-17 11:42北京
全部评论
最多点赞
最新发布
最早发布
阿福采纳答复
modifier: 内容修改器,开发者需要自定义class实现ContentModifier接口。
- 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")
- }
- }
- }
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) } }展开全部1
2024-08-18 04:32 来自浙江
阿福回复Jelly
写回答
所见即所得编辑器, editor1
工具栏 撤消 快捷键 Ctrl+Z 重做 快捷键 Ctrl+Y 格式刷 快捷键 Ctrl+Shift+C 清除格式 加粗 快捷键 Ctrl+B 倾斜 快捷键 Ctrl+I 下划线 快捷键 Ctrl+U 删除线格式调整字号 文本颜色 背景颜色 增加缩进量 减少缩进量 左对齐 居中 右对齐 两端对齐段落间距行间距 项目列表 编号列表 插入水平线 块引用 插入/编辑超链接 快捷键 Ctrl+K 取消超链接 图片 表格 上传附件 导入Word 插入代码 MD编辑器 全屏模式
0/50000
新增插入模板功能
一键使用模板,快速填写内容,轻松发帖~
知道了
- 为了保障您的信息安全,请勿上传您的敏感个人信息(如您的密码等信息)和您的敏感资产信息(如关键源代码、签名私钥、调试安装包、业务日志等信息),且您需自行承担由此产生的信息泄露等安全风险。
- 如您发布的内容为转载内容,请注明内容来源。
我要提问题
相关推荐
换一批
1
HarmonyOS 目前是否有组件支持markdown数据展示(API12+)
2
HarmonyOS this是builder对象,获取this的属性值为undefined(API12+)
3
HarmonyOS 如何实现一个自动换行的组件(API12+)
4
HarmonyOS 如何实现组件内边缘的发光阴影效果?(API12+)
5
HarmonyOS 如何使用数据面板组件DataPanel (API12+)
6
HarmonyOS 自定义组件怎么使用Column的属性 (API12+)
7
如何使用Web实现表格组件
8
HarmonyOS RichEditor组件能否通过动态属性attributeModifier来修改placeholder属性 (API12+)
了解社区公约,与您携手共创和谐专业的开发者社区。




































苏公安网备 32011402010933号