当前位置: 首页 > news >正文

建设银行河北招聘网站重庆seo论坛

建设银行河北招聘网站,重庆seo论坛,中国房地产行情分析,php怎么做搭建网站【HarmonyOS】List组件多层对象嵌套ForEach渲染更新的处理 问题背景: 在鸿蒙中UI更新渲染的机制,与传统的Android IOS应用开发相比。开发会简单许多,开发效率提升显著。 一般传统应用开发的流程处理分为三步:1.画UI,…

【HarmonyOS】List组件多层对象嵌套ForEach渲染更新的处理

问题背景:
在鸿蒙中UI更新渲染的机制,与传统的Android IOS应用开发相比。开发会简单许多,开发效率提升显著。

一般传统应用开发的流程处理分为三步:1.画UI,2.获得or创建,处理数据,3.增删改数据,找到对应控件,更新到UI上。

而鸿蒙应用开发,大大提供效率其中一点,就是减少了第三步。我们只需要关心数据源的变化,数据自动会更新到对应的控件上。

这种处理机制,其实符合应用开发的时代潮流,目前Android和IOS最新框架机制都有相应类似的处理。例如swiftUI,Compose。并且Vue,Flutter整个刷新机制就是如此。

众所周知,在HarmonyOs的list组件渲染中,如果数据源列表对象是多个对象嵌套的处理,那最底层对象的属性更新时,UI界面是不会渲染的。因为检测不到,目前只能检测到第一层对象。

解决方案:

当然官方的api在持续迭代的过程中。对于冗余渲染,渲染的性能提升,还有多层对象嵌套的数据源更新问题,一直再迭代方法处理。

针对多层对象嵌套,底层对象属性修改后,UI不渲染的问题,有个比较简单又方便的处理方式,思路仅供参考。

即:深拷贝修改的item对象。

这样整个对象相当于都变化了,就符合第一层对象检测的机制,可以被系统捕获到刷新。

DEMO示例:

import { util } from '@kit.ArkTS';/*** 二级数据结构*/
class ChildInfo {index: number;constructor(index: number) {this.index = index;}
}/*** 一级数据结构*/
class ItemInfo {key: string = util.generateRandomUUID(true);name: string;icon: Resource;childInfo: ChildInfo;select: boolean;constructor(name: string, icon: Resource, index: number) {this.name = name;this.icon = icon;this.childInfo = new ChildInfo(index);this.select = false;}/*** 重新创建对象,深拷贝处理* @param itemInfo* @param index* @returns*/static deepCopy(itemInfo: ItemInfo, index: number){let info: ItemInfo = new ItemInfo(itemInfo.name, itemInfo.icon, index);info.select = itemInfo.select;info.key = itemInfo.key;info.childInfo = itemInfo.childInfo;return info;}
}/****/


struct ForeachPage {private TAG: string = "ForeachPage"; mListData: Array<ItemInfo> = [];aboutToAppear(): void {this.mListData.push(new ItemInfo('游戏', $r("app.media.iconA"), 1));this.mListData.push(new ItemInfo('游戏', $r("app.media.iconB"), 2));this.mListData.push(new ItemInfo('游戏', $r("app.media.iconA"), 3));this.mListData.push(new ItemInfo('游戏', $r("app.media.iconB"), 4));this.mListData.push(new ItemInfo('游戏', $r("app.media.iconA"), 5));this.mListData.push(new ItemInfo('游戏', $r("app.media.iconB"), 6));} ItemView(item: ItemInfo, index: number){Row() {Image(item.icon).width(px2vp(120)).height(px2vp(120))Text(item.name + "(" + item.childInfo.index + ")").fontSize(20)Blank()if(this.isLog(item, index)){if(item.select){Image($r("app.media.icon_check")).size({width: px2vp(72),height: px2vp(72)})}}}.width('100%').justifyContent(FlexAlign.Start).onClick(()=>{item.select = !item.select;if(item.select){item.childInfo.index = 666;}else{item.childInfo.index = index;}this.mListData[index] = ItemInfo.deepCopy(item, item.childInfo.index);console.log(this.TAG, " ItemView onClick: " + index + " item.select: " + item.select);})}private isLog(item: ItemInfo, index: number){console.log(this.TAG, " ItemView isLog index: " + index + " item.select: " + item.select);return true;}build() {List() {ForEach(this.mListData, (item: ItemInfo, index: number) => {ListItem() {this.ItemView(item, index)}}, (item: ItemInfo) => JSON.stringify(item))//}.width("100%").height("100%").padding({ left: px2vp(60), right: px2vp(60) })}
}

iconA
iconB
icon_check

http://www.hkea.cn/news/561367/

相关文章:

  • 电子商务的网站建设牛排seo系统
  • 资源收费网站怎么做网站快速优化排名官网
  • 招标网哪个网站信息可靠百度站长工具网站
  • 郑州七七网站建设互联网推广公司
  • 佛山做外贸网站代理商百度收录技术
  • 公司网站建设需要什么今日热搜第一名
  • 烟台建设企业网站网站快速收录入口
  • 怎么做繁体字网站网络营销公司注册找哪家
  • 做ppt介绍网站吗网站搜索引擎优化工具
  • 深圳网站建设有没有市场百度搜索推广的五大优势
  • 网站建设好的图片百度互联网营销
  • 柳州网站制作公司seo优化什么意思
  • 网站建设做的好的公司淘宝关键词优化怎么弄
  • 手机网站用模版方象科技的企业愿景
  • 沈阳网站建设技术公司排名公司市场营销策划方案
  • 赣州网站建设怎样石家庄最新消息
  • 公司注册地址和经营地址不一致可以吗长春seo招聘
  • 好的做问卷调查的网站好推广有奖励的app平台
  • 有专业设计网站吗百度指数与百度搜索量
  • 网站的整体结构百度云网盘资源搜索引擎入口
  • 咸阳网站建设哪家专业杭州优化公司在线留言
  • 地板网站建设门户网站
  • 新增备案网站负责人人工智能培训心得体会
  • 帮境外赌场做网站是否有风险百度企业号
  • 网站换了服务器百度seo排名优化公司哪家好
  • 海南网站建设制作网络营销效果评估
  • 飞阳建设网站上海广告公司
  • 营销网站导航栏常见网站搜索排名靠前
  • 深圳市政府网站官网百度地图疫情实时动态
  • 上海建设工程咨询网 首页深圳优化排名公司