HarmonyOS鸿蒙Next中页面布局中,数据绑定,界面刷新问题
HarmonyOS鸿蒙Next中页面布局中,数据绑定,界面刷新问题 有这一样个数据对象
export default class InfoData { dataBaseInfo : RowInfo[] = []; dataTime : RowInfo[] =[]; }
在页面上这样使用
@State infoData: InfoData = new InfoData (); ForEach(this.infoData.dataBaseInfo, (row: RowInfo) => { Row() { ForEach(row.cellInfo, (cell: CellInfo) => { Text(cell.text) .textAlign(cell.textAlign) .layoutWeight(cell.layoutWeight) .fontWeight(cell.fontWeight) .fontSize(cell.fontSize) .fontColor(cell.fontColor) .padding({ top: 8, bottom: 8 }) .id(“edt_” + row.row + “_” + cell.col) .onClick(() => { if (cell.col == 0) return; this.infoData.dataBaseInfo= Helper.refData(this.infoData.dataBaseInfo, row.row, cell.col); }); } .backgroundColor(row.backgroundColor) .justifyContent(FlexAlign.Start) }); }
点击事件的会调用Helper.refData()刷新dataBaseInfo里面的数据,现在也执行了刷新方法,可界面没有刷新
如果单独定义dataBaseInfo : RowInfo[] = []; 界面上绑定this.dataBaseInfo,则界面会刷新,请问这是什么原因?
更多关于HarmonyOS鸿蒙Next中页面布局中,数据绑定,界面刷新问题的实战教程也可以访问 https://www.itying.com/category-93-b0.html
this.infoData.dataBaseInfo= Helper.refData(this.infoData.dataBaseInfo, row.row, cell.col); 这里改成这样 this.infoData = Helper.refData(this.infoData, row.row, cell.col); 解决了,哈哈,昨晚上突然想到,搞不懂原因
更多关于HarmonyOS鸿蒙Next中页面布局中,数据绑定,界面刷新问题的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
HarmonyOS Next中数据绑定采用ArkTS声明式UI范式,通过@State、@Link等装饰器管理状态。页面刷新由框架自动触发,当装饰器标记的变量值变更时,关联的UI组件会自动更新。使用@Observed和@ObjectLink可管理嵌套对象。


