代码:
interface amt{
amt:string;// 金额
ischeck:boolean;//选择状态
}
@State amtList:Array<amt>=[];// 充值金额选择
let amtList=[] as Array<amt>
if(res3.payAmtLst.length>0){
res3.payAmtLst.map((item,index)=>{
amtList.push({
amt:`${parseInt(item.amt)/1000}元`,
ischeck:index==0?true:false
} as amt)
})
}
UI代码:
ForEach(this.amtList,(item:amt,index:number)=>{
Text(item.amt).onClick(()=>{
for(let i =0;i<this.amtList.length;i++){
this.amtList[i].ischeck=index==i?true:false
}
console.log(JSON.stringify(this.amtList))
})
})
数组数据变更了但未触发视图刷新,这个问题需要怎么处理
@State装饰器不会响应深层次数组项子属性变化。请参考一下这个用例:
https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/arkts-rendering-control-foreach-V5\#数据源数组项子属性变化