HarmonyOS DataSource数据发生变化,Tabs循环的tabContent未发生变化
代码如下:
@Preview
@Component
export struct TextPreLayout {
testArry: string[] = ["页面1", "页面2", "页面3", "页面4"]
@State dataSource: LazyDataSource<string> = new LazyDataSource();
@State listArr: string[] = [];
private tabController: TabsController = new TabsController();
@State currentPage: number = 2;
aboutToAppear() {
for (let i = 0; i < this.testArry.length; i++) {
this.dataSource.pushData(this.testArry[i]);
}
}
changeData() {
this.testArry = ["页面2", "页面1", "页面3", "页面4"]
this.dataSource.clear();
for (let i = 0; i < this.testArry.length; i++) {
this.dataSource.pushData(this.testArry[i]);
}
}
build() {
Column() {
Text("改变dataSource")
.width(160)
.height(30)
.backgroundColor('#fcc')
.fontColor('#f00')
.onClick(() => {
this.changeData()
})
.margin({ top: 40, left: 40, bottom: 10 })
List() {
LazyForEach(this.dataSource, (column: string, index: number) => {
this.TabBuilder(column, index)
}, (item: string) => JSON.stringify(item))
}
.edgeEffect(EdgeEffect.None)
// 设置左对齐
.align(Alignment.Start)
.listDirection(Axis.Horizontal)
.scrollBar(BarState.Off)
.padding({ right: 5, left: 5 })
.backgroundColor($r('app.color.uicp_FFFFFF_1A2026'))
.width('100%')
.height(32)
Tabs({ index: this.currentPage }) {
LazyForEach(this.dataSource, (column: string) => {
TabContent() {
ChannelTextIndexView({
channelName: column
})
}
}, (item: string) => JSON.stringify(item))
}
.barHeight(0)
.barBackgroundColor($r('app.color.color_FFFFFF_1A2026'))
.scrollable(true)
.onChange((index) => {
this.currentPage = index;
})
}
}
@Builder
TabBuilder(name: string, index: number) {
Text(name)
.width(60)
.height(30)
.fontColor('#f00')
.onClick(() => {
console.debug('AAAA', "homeIndex TabBuilder onClick index=" + index);
this.currentPage = index;
})
.fontSize(this.currentPage === index ? 18 : 16)
.fontWeight(this.currentPage === index ? FontWeight.Bold :
FontWeight.Normal)//设置文本的字体粗细,number类型取值[100, 900],取值间隔为100,取值越大,字体越粗,默认值:400 | FontWeight.Normal
.fontColor(this.currentPage === index ? $r('app.color.uicp_E10000') : $r('app.color.uicp_333333_6B758E'))
}
}
@Component
export struct ChannelTextIndexView {
channelName: string = "";
aboutToAppear(): void {
}
build() {
Column() {
Text(this.channelName)
Text(this.channelName)
Text(this.channelName)
Text(this.channelName)
Text(this.channelName)
Text(this.channelName)
Text(this.channelName)
Text(this.channelName)
}.width("100%").height("100%")
}
}
HarmonyOS
赞
收藏 0
回答 1
待解决
相关问题
HarmonyOS 页面高度发生变化
418浏览 • 1回复 待解决
HarmonyOS 基础组件渲染的内容发生变化 添加fade动画
117浏览 • 1回复 待解决
网站.net改PHP,链接发生变化怎么设置301跳转?
2178浏览 • 0回复 待解决
后续异常信息是否会根据版本的迭代发生变化?
816浏览 • 1回复 待解决
HarmonyOS WaterFlow数据更新后,使用scrollToIndex(0)后,瀑布流数据发生变化
242浏览 • 1回复 待解决
HarmonyOS ArkTS堆栈格式结构?后续ArkTS堆栈结构是否会发生变化?
261浏览 • 1回复 待解决
HarmonyOS Canvas的在onReady函数里link对象发生变化并不会重新走判断
65浏览 • 1回复 待解决
#鸿蒙学习大百科#如何实现父组件尺寸发生变化,但是子组件的宽高比不变化?
407浏览 • 0回复 待解决
web组件嵌套滚动在折叠屏展开后收起时其滚动位置会发生变化
355浏览 • 1回复 待解决
BundleInfo.appInfo.accessTokenId使用过程中是否会发生变化
2151浏览 • 1回复 待解决
HarmonyOS 数组中嵌套对象的属性值发生变化,@Watch监听不到数组的变化,这个要怎么办
171浏览 • 1回复 待解决
User-Agent的取值是什么,是否会随着系统升级而发生变化
2427浏览 • 1回复 待解决
HarmonyOS 容器组件子组件个数发生变化时,有什么监听回调方法吗
133浏览 • 1回复 待解决
HarmonyOS使用调试证书和发布证书两种情况下 应用的appId会发生变化吗?
307浏览 • 1回复 待解决
#鸿蒙学习大百科#当组件的布局属性发生变化,对于UI的刷新有什么影响?
395浏览 • 1回复 待解决
#鸿蒙学习大百科#当组件的绘制属性发生变化(color,opacity等)对UI的刷新有什么影响?
416浏览 • 1回复 待解决
目前键盘弹出会自动调整布局,希望能设置键盘弹出后,布局不发生变化
2325浏览 • 1回复 待解决
使用@LocalStorageProp修饰的变量,当子组件中的变量值变了,@Entry页面中的值没有发生变化。
713浏览 • 1回复 待解决
当网络请求的数据源对象的内容发生变更后,所有图片都会一闪而过;如果数据源的内容没变,就不会发生
630浏览 • 1回复 待解决
HarmonyOS Tabs组件在滑动过程中监听TabContent位置变化
51浏览 • 1回复 待解决
HarmonyO foreach循环,数据变化了,界面没有刷新
592浏览 • 1回复 待解决
HarmonyOS 使用@ohos.ArkUI.observer进行无感监听路由变化如何获取路由变化发生在哪个窗口呢?
634浏览 • 1回复 待解决
是否需要在应用发布签名发生变更,应用版本更新后,手机用户先卸载原来的应用才能安装
893浏览 • 1回复 待解决
数据庞大复杂时可能会出现性能问题,Tabs组件不支持LazyForEach(实际上也是一次性加载),所以实际渲染应该和ForEach一样,如果遇到加载缓慢可以尝试优化数据源或数据结构,参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/arkts-rendering-control-lazyforeach-V5#使用限制