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'))
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
- 67.
- 68.
- 69.
- 70.
- 71.
- 72.
- 73.
- 74.
- 75.
- 76.
- 77.
- 78.
- 79.
- 80.
- 81.
- 82.
- 83.
- 84.
- 85.
- 86.
- 87.
- 88.
- 89.
@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%")
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
HarmonyOS
赞
收藏 0
回答 1
相关问题
HarmonyOS 页面高度发生变化
936浏览 • 1回复 待解决
HarmonyOS 基础组件渲染的内容发生变化 添加fade动画
664浏览 • 1回复 待解决
HarmonyOS WaterFlow数据更新后,使用scrollToIndex(0)后,瀑布流数据发生变化
798浏览 • 1回复 待解决
网站.net改PHP,链接发生变化怎么设置301跳转?
2689浏览 • 0回复 待解决
后续异常信息是否会根据版本的迭代发生变化?
1259浏览 • 1回复 待解决
HarmonyOS ArkTS堆栈格式结构?后续ArkTS堆栈结构是否会发生变化?
700浏览 • 1回复 待解决
BundleInfo.appInfo.accessTokenId使用过程中是否会发生变化
2830浏览 • 1回复 待解决
User-Agent的取值是什么,是否会随着系统升级而发生变化
3038浏览 • 1回复 待解决
HarmonyOS 容器组件子组件个数发生变化时,有什么监听回调方法吗
727浏览 • 1回复 待解决
HarmonyOS Canvas的在onReady函数里link对象发生变化并不会重新走判断
598浏览 • 1回复 待解决
#鸿蒙学习大百科#如何实现父组件尺寸发生变化,但是子组件的宽高比不变化?
927浏览 • 0回复 待解决
web组件嵌套滚动在折叠屏展开后收起时其滚动位置会发生变化
849浏览 • 1回复 待解决
HarmonyOS 数组中嵌套对象的属性值发生变化,@Watch监听不到数组的变化,这个要怎么办
794浏览 • 1回复 待解决
HarmonyOS使用调试证书和发布证书两种情况下 应用的appId会发生变化吗?
998浏览 • 1回复 待解决
目前键盘弹出会自动调整布局,希望能设置键盘弹出后,布局不发生变化
2774浏览 • 1回复 待解决
#鸿蒙学习大百科#当组件的布局属性发生变化,对于UI的刷新有什么影响?
767浏览 • 1回复 待解决
使用@LocalStorageProp修饰的变量,当子组件中的变量值变了,@Entry页面中的值没有发生变化。
1192浏览 • 1回复 待解决
#鸿蒙学习大百科#当组件的绘制属性发生变化(color,opacity等)对UI的刷新有什么影响?
779浏览 • 1回复 待解决
当网络请求的数据源对象的内容发生变更后,所有图片都会一闪而过;如果数据源的内容没变,就不会发生
1114浏览 • 1回复 待解决
是否需要在应用发布签名发生变更,应用版本更新后,手机用户先卸载原来的应用才能安装
1481浏览 • 1回复 待解决
HarmonyOS 使用@ohos.ArkUI.observer进行无感监听路由变化如何获取路由变化发生在哪个窗口呢?
1288浏览 • 1回复 待解决
HarmonyOS Tabs组件在滑动过程中监听TabContent位置变化
718浏览 • 1回复 待解决
HarmonyO foreach循环,数据变化了,界面没有刷新
1309浏览 • 1回复 待解决
数据庞大复杂时可能会出现性能问题,Tabs组件不支持LazyForEach(实际上也是一次性加载),所以实际渲染应该和ForEach一样,如果遇到加载缓慢可以尝试优化数据源或数据结构,参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/arkts-rendering-control-lazyforeach-V5#使用限制