HarmonyOS鸿蒙Next中bindermenu是否支持参数
HarmonyOS鸿蒙Next中bindermenu是否支持参数
@Builder RepeatMenu(itemList:string[]) { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center }) { ForEach(itemList, (item: string) => { Row(){ Text(item) .height(32) .fontWeight(400) .fontSize(14) .fontColor(Color.Black) .margin(5) } .onClick(() => { this.repeatBase = item }) }) } } @Builder SelectBar(content:CustomBuilder){ Row(){ Text(this.repeatBase) .fontWeight(400) .fontSize(14) .fontColor(Color.Gray) .margin({right:5}) SymbolGlyph($r(‘sys.symbol.chevron_right’)) .fontWeight(FontWeight.Normal) .fontSize(24) .fontColor([’#DADADA’, Color.Gray, Color.Gray]) } .position({ top: 17,right:0}) .bindMenu(content) }
Item直接显示出来了
更多关于HarmonyOS鸿蒙Next中bindermenu是否支持参数的实战教程也可以访问 https://www.itying.com/category-93-b0.html
使用的地方
this.SelectBar(this.RepeatMenu(this.repeatList))
更多关于HarmonyOS鸿蒙Next中bindermenu是否支持参数的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
在HarmonyOS鸿蒙Next中,bindermenu确实支持参数传递。bindermenu是鸿蒙的跨进程通信机制,开发者可以通过Intent或Want对象传递参数数据。参数类型支持基本数据类型、对象以及Parcelable序列化数据。参数传递方式与其他鸿蒙API保持一致,需在Want中设置参数键值对。具体参数限制取决于Binder通信的缓冲区大小,通常不超过1MB。参数在跨进程传递时会自动序列化和反序列化。
在HarmonyOS Next中,bindMenu
确实支持参数传递。从您提供的代码来看,问题可能出在SelectBar
组件的使用方式上。
您的RepeatMenu
是一个带参数的@Builder
函数,但在SelectBar
中直接将其作为CustomBuilder
类型参数传递时,没有正确传递所需的itemList
参数。正确的做法应该是:
- 修改
SelectBar
定义,使其能接收并传递参数:
@Builder
SelectBar(contentBuilder: () => void) {
Row(){
// ...原有代码
}
.bindMenu(contentBuilder)
}
- 使用时应该这样调用:
SelectBar(() => {
this.RepeatMenu(['item1', 'item2', 'item3'])
})
这样就能确保菜单内容在显示时能正确接收参数。当前您的实现方式会导致菜单内容在初始化时就立即渲染,而不是在点击时渲染。