嵌套在List组件的子List组件不能触发onReachEnd(HarmonyOS 鸿蒙Next)
嵌套在List组件的子List组件不能触发onReachEnd(HarmonyOS 鸿蒙Next)
numberCount: Array<number> = [1,2,3,4,5]
build() { Row() { List() { ForEach(this.numberCount, (item: number) => { ListItem() { this.settingCell(item) } .height(120) }) } .backgroundColor(Color.White) .width(‘100%’) .height(‘60%’) .divider({ strokeWidth:0.25, color: Color.Grey, startMargin: 42, endMargin: 24 }) .borderRadius(16) .padding({ top: 4, bottom: 4 }) .onReachEnd( () => { console.log(‘外部list’) }) } .height(‘100%’) }
@Builder settingCell(item: number) { List() { ForEach(this.numberCount, (item: number) => { ListItem() { Text(
${item}
) .fontSize(24) } .height(30) })
} .backgroundColor(Color.Yellow) .width(‘80%’) .onReachEnd( () => { console.log(‘内部list’) }) }
<button style="position: absolute; padding: 4px 8px 0px; cursor: pointer; top: 8px; right: 8px; font-size: 14px;">复制</button>
更多关于嵌套在List组件的子List组件不能触发onReachEnd(HarmonyOS 鸿蒙Next)的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
在HarmonyOS鸿蒙Next的开发环境中,嵌套List组件时子List组件无法触发onReachEnd
事件,通常是由于事件冒泡或事件捕获机制处理不当导致的。以下是一些可能的原因及解决方案:
-
事件冒泡:确保子List组件的
onReachEnd
事件没有被父List组件或其他中间层组件拦截。可以通过在子List组件上设置stopPropagation
来阻止事件冒泡,确保事件能够正确触发。 -
滚动冲突:检查父List组件和子List组件的滚动设置,确保它们不会相互干扰。如果父List组件的滚动被禁用或限制,可能会影响子List组件的滚动事件。
-
组件嵌套层级:确认组件的嵌套层级是否合理,过深的嵌套有时会导致事件处理异常。尝试简化组件结构,看是否能解决问题。
-
版本兼容性:检查HarmonyOS鸿蒙Next的SDK版本,确保你使用的版本支持嵌套List组件的
onReachEnd
事件。有时,SDK的更新会修复此类问题。
如果问题依旧没法解决请联系官网客服,官网地址是:https://www.itying.com/category-93-b0.html 。