HarmonyOS 嵌套层级较多,导致状态管理不能刷新UI
List其中一个ListItem是swiper,swiper中一个item使用了ForEach渲染了2行item。更新最后2行Item中的某一个字段,UI不更新。
let subPickData = this.mergeCellData?.cells[0] as SubPickData
let moneyPickData = subPickData.cell[0] as MoneyPickData;
moneyPickData.plateName = '+' + (Math.random() * 100).toFixed(2) + "%";
moneyPickData.plateChangeRate = '+' + (Math.random() * 100).toFixed(2) + "%";
下面贴出bean的代码:
@Observed
export class MergeCellData implements CellType {
cardData?: CardData;
itemType: ItemType;
key?: string;
cells: ObservedArray<SubPickData | SubEvaluateData> = new ObservedArray();
titles: string[] = [];
}
@Observed
export class SubPickData {
subCardData: SubCardData;
cell: ObservedArray<MoneyPickData|NewsPickData|BasicPickData|TechnologyPickData> = new ObservedArray();
}
@Observed
export class MoneyPickData {
plateCode: string;
downCount: number;
flatCount: number;
}
@Observed
export class ObservedArray<T> extends Array<T> {
constructor(args?: T[]) {
if (args instanceof Array) {
super(...args);
} else {
super();
}
}
}
下面贴出UI代码:
export struct ChooseStockItem {
@ObjectLink @Watch('update') data: MergeCellData;
build() {
Column() {
Swiper(this.controller) {
ForEach(this.data?.cells, (subData: SubPickData) => {
if (subData.subCardData.cardCode == MONEY_PICK) {
MoneyPickView({ data: subData.cell })
.padding({
top: 7,
bottom: 16
})
} else if (subData.subCardData.cardCode == NEWS_PICK) {
NewsPickView({ data: subData.cell })
.padding({
top: 7,
bottom: 16
})
} else if (subData.subCardData.cardCode == BASIC_PICK) {
BasicPickView({ data: subData.cell, jumpUrl: subData.subCardData.jumpUrl })
.padding({
top: 7,
bottom: 16
})
} else if (subData.subCardData.cardCode == TECHNOLOGY_PICK) {
TechnologyPickView({ data: subData.cell, jumpUrl: subData.subCardData.jumpUrl })
.padding({
top: 7,
bottom: 16
})
}
}, (subData: SubPickData, index: number) => index.toString() + subData.subCardData.cardCode)
}
.onAppear(() => {
XFLog.e("x", "== MoneyPickViewItem Swiper ChooseStockItem onAppear == ");
})
.onChange((index: number) => {
this.swiperHeight = undefined
this.currentIndex = index;
})
.onAreaChange((_oldValue: Area, newValue: Area) => {
this.swiperHeight = newValue.height
})
.width('100%')
.height(this.swiperHeight)
.displayCount(1, true)
.index($$this.currentIndex)
.autoPlay(false)
.indicator(false)
.cachedCount(4)
.loop(false)
}
}
}
@Reusable
@Component
export struct MoneyPickView {
@ObjectLink @Watch('update') data: ObservedArray<MoneyPickData | NewsPickData | BasicPickData | TechnologyPickData>;
build() {
Column() {
ForEach(this.data, (item: MoneyPickData, index: number) => {
MoneyPickViewItem({ data: item, index: index })
}, (index: number) => index + '__')
}
}
update(changedPropertyName: string) {
XFLog.e("x","MoneyPickViewItem MoneyPickView data == ");
}
}
@Reusable
@Component
struct MoneyPickViewItem {
@ObjectLink data: MoneyPickData
@Prop index: number
build() {
Column() {
Row() {
Text(this.data.fundName)
.alignSelf(ItemAlign.Start)
.fontSize(14)
.fontColor($r('app.color.text_level2'))
.onAppear(() => {
XFLog.e("x","MoneyPickViewItem Text onAppear fundName == "+this.data.fundName);
})
if (this.data.fundJumpUrl) {
Image($r('app.media.icon_homepage_right_arrow'))
.width(16)
.height(16)
.margin({ left: 2 })
.onAppear(() => {
XFLog.e("x","MoneyPickViewItem Image onAppear fundName == "+this.data.fundName);
})
// .syncLoad(true)
}
}
}
.alignItems(HorizontalAlign.Start)
.margin({ top: getItemSpace(this.index) })
.padding({ left: 16, right: 16 })
}
}
HarmonyOS
赞
收藏 0
回答 1
待解决
相关问题
HarmonyOS 嵌套数组元素的UI刷新方案
230浏览 • 1回复 待解决
状态装饰器 ui不刷新的问题
2292浏览 • 1回复 待解决
HarmonyOS 下拉刷新组件,顶部padding会导致下拉刷新的UI暴露出来
207浏览 • 1回复 待解决
#鸿蒙学习大百科#在状态管理中,如何避免非必要的UI视图刷新?
125浏览 • 1回复 待解决
HarmonyOS 状态管理咨询
233浏览 • 1回复 待解决
HarmonyOS ObjectLink修饰符对象的属性改变不能引起UI刷新
304浏览 • 1回复 待解决
HarmonyOS Array 成员变量属性更改,状态不同步、未能刷新UI
404浏览 • 1回复 待解决
HarmonyOS 主线程刷新UI
89浏览 • 1回复 待解决
HarmonyOS List嵌套不能同步数据
197浏览 • 1回复 待解决
HarmonyOS scroll嵌套List不能整体滑动
165浏览 • 1回复 待解决
HarmonyOS UI 未刷新问题
273浏览 • 0回复 待解决
HarmonyOS 新状态管理框架@observed、@track
397浏览 • 1回复 待解决
UI预览不会自动刷新, 且刷新较慢
331浏览 • 1回复 待解决
嵌套ForEach不能自动适应高度
572浏览 • 1回复 待解决
HarmonyOS 状态管理-父子组件同步的问题
362浏览 • 1回复 待解决
HarmonyOS 对象A数组,对象A中又嵌套一个对象B数组,修改B中的属性UI,不刷新
303浏览 • 1回复 待解决
Swiper 组件嵌套图片刷新数据会闪烁
1051浏览 • 1回复 待解决
IF条件变化后UI不刷新
581浏览 • 1回复 待解决
求告知如何强制刷新UI?
217浏览 • 1回复 待解决
#鸿蒙学习大百科#嵌套类中的属性如何才能具有触发UI刷新的能力?
82浏览 • 1回复 待解决
刷新显示状态,希望自定义一个刷新组件,通过刷新状态的不同显示不同字段包括下拉刷新,释放刷新
726浏览 • 1回复 待解决
HarmonyOS @Extend和@Styles不能导出,导致项目开发样式不能共用,只能依托于组件
288浏览 • 0回复 待解决
obd升级后导致obproxy服务不能启动
4859浏览 • 1回复 待解决
HarmonyOS refresh组件下拉刷新是不是不能自定义顶部刷新时的样式?
168浏览 • 1回复 待解决
#鸿蒙学习大百科#状态变量的变化何时会触发UI刷新?
124浏览 • 1回复 待解决
参考一下@Builder装饰器,按引用传递参数时,传递的参数可为状态变量,且状态变量的改变会引起@Builder方法内的UI刷新:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/arkts-builder-V5#%E6%8C%89%E5%BC%95%E7%94%A8%E4%BC%A0%E9%80%92%E5%8F%82%E6%95%B0