HarmonyOS 关于数组包裹对象中更新组件问题
以下代码中Info对象中real_name字段期望点击griditem的时候更新reanl_name信息这个如何实现啊,目前是数组更新了,但是real_name没及时更新。
import { ObservedArray } from '@ohos/common'
@Preview
@Component
export struct GridTest {
@State beanList: ObservedArray<Info> = []
aboutToAppear(): void {
this.beanList.push(new Info("1"))
this.beanList.push(new Info("2"))
this.beanList.push(new Info("3"))
this.beanList.push(new Info("4"))
this.beanList.push(new Info("5"))
this.beanList.push(new Info("6"))
this.beanList.push(new Info("7"))
}
build() {
Column() {
Grid() {
ForEach(this.beanList, (item: Info, index) => {
GridItem() {
Column() {
Text(item.real_name)
.fontColor($r('app.color.scaffold_fg_dark_2'))
.fontSize(12)
.padding({ top: 5, bottom: 2 })
.maxLines(1)
.textAlign(TextAlign.Center)
.visibility(Visibility.Visible)
}
}.borderRadius(8)
.size({width:80,height:80})
.backgroundColor(Color.Red)
.borderWidth(0).onClick(() => {
this.beanList[index].real_name = index + "SS"
console.log("-----onClick-grid---" + this.beanList[index].real_name + ",," + item.real_name)
})
}, (item: Info) => JSON.stringify(item))
}
.rowsGap(10)
.columnsGap(16)
.padding({
bottom: 12,
top: 10
})
}.width("100%").backgroundColor($r('app.color.color_ffffff'))
}
}
@Observed
export class Info {
constructor(real_name: string) {
this.real_name = real_name
}
real_name?: string = '';
}
HarmonyOS
赞
收藏 0
回答 1
待解决
相关问题
HarmonyOS 关于数组中class更改,List不触发更新问题
565浏览 • 1回复 待解决
HarmonyOS 对象数组在使用@Observed和@ObjectLink驱动子组件UI更新时的问题
612浏览 • 1回复 待解决
HarmonyOS 对象内数组排序问题
411浏览 • 1回复 待解决
HarmonyOS 数组中对象的排序
513浏览 • 1回复 待解决
HarmonyOS @Observed装饰的类,构造了对象数组,那这个数组中对象的属性变化之后,能引起视图的更新吗
1506浏览 • 1回复 待解决
HarmonyOS 对象内数组内对象属性的修改问题
322浏览 • 1回复 待解决
HarmonyOS 关于WrapperBuilder更新问题
282浏览 • 1回复 待解决
HarmonyOS 对象A数组,对象A中又嵌套一个对象B数组,修改B中的属性UI,不刷新
990浏览 • 1回复 待解决
HarmonyOS 如何实现根据数组元素对象属性的变化同步更新UI
411浏览 • 1回复 待解决
HarmonyOS 关于对象数组内容变更不会引起UI刷新
790浏览 • 0回复 待解决
HarmonyOS 关于objectLink在数组对象中使用时,修改数据页面不刷新问题
1144浏览 • 1回复 待解决
关于发布证书更新的问题
724浏览 • 1回复 待解决
HarmonyOS viewModel中获取数组数据,怎么更新ui
213浏览 • 1回复 待解决
HarmonyOS 关于APP版本升级更新的问题
259浏览 • 1回复 待解决
HarmonyOS关于JSVM中创建原生对象的生命周期问题
637浏览 • 1回复 待解决
如何判断一个对象是否在对象数组中
2830浏览 • 1回复 待解决
HarmonyOS 数组对象数据刷新
420浏览 • 1回复 待解决
HarmonyOS Navigation包裹Splash界面显示问题
389浏览 • 1回复 待解决
HarmonyOS 使用tab组件,列表对象如何动态更新内容。
687浏览 • 1回复 待解决
#鸿蒙通关秘籍#如何在HarmonyOS中通过BaseNavigation包裹子组件
363浏览 • 1回复 待解决
HarmonyOS @State可以修饰对象数组
321浏览 • 1回复 待解决
HarmonyOS Scroll包裹的控件默认居中问题
689浏览 • 1回复 待解决
HarmonyOS 分组列表数组嵌套时数据更新不触发列表更新
414浏览 • 1回复 待解决
HarmonyOS @state可以修饰对象数组么
308浏览 • 1回复 待解决
HarmonyOS 关于合并对象
237浏览 • 2回复 待解决
请参考下方代码:
每个属性都要实例化,通过json解析,ArkUI无法监听对象中数组属性的push变化,json解析的为非class对象,class内的属性变化不能被观察到。