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

创建网站投资多少钱赶集网的二级域名网站怎么做

创建网站投资多少钱,赶集网的二级域名网站怎么做,网站下载免费软件安装,我要设计网【HarmonyOS】Observed和ObjectLink嵌套对象属性更改UI不刷新问题 一、问题背景 使用了Observed和ObjectLink#xff0c;修改嵌套对象的属性#xff0c;UI还是不刷新#xff0c;常见的问题有以下三种形式#xff1a; 1.多级嵌套#xff0c;嵌套对象的类并没有添加Observ…【HarmonyOS】Observed和ObjectLink嵌套对象属性更改UI不刷新问题 一、问题背景 使用了Observed和ObjectLink修改嵌套对象的属性UI还是不刷新常见的问题有以下三种形式 1.多级嵌套嵌套对象的类并没有添加Observed进行监听 2.多级嵌套嵌套对象的View组件没有抽离出来添加ObjectLink进行该级对象的监听绑定 3.嵌套对象并没有new出来创建直接赋值没有创建对象的过程无法激活Observed监听 二、代码举例 以代码示例举例 1.创建了接口TestInfoInterFace 父类TestInfo嵌套类TestItem 。 interface TestInfoInterFace {name: string;items: TestItem[]; }class TestItem {content: string ;isClicked: boolean false; }Observed class TestInfo {name: string;items: TestItem[];constructor(name: string, items: TestItem[]) {this.name name;this.items items;} } 2.添加测试数据渲染列表单元格数据基本类型结构为TestInfo。 Entry Component struct TestPage {State mTestDataArr: TestInfo[] [new TestInfo(测试数据1, [{content: 单元数据1,isClicked: false}, {content: 单元数据1,isClicked: false}]),new TestInfo(测试数据2, [{content: 单元数据1,isClicked: false}, {content: 单元数据1,isClicked: false}]),new TestInfo(测试数据3, [{content: 单元数据1,isClicked: false}, {content: 单元数据1,isClicked: false}]),]build() {Column() {ForEach(this.mTestDataArr, (item: TestInfoInterFace) {ChildView({mTestInfo: item})})}.width(100%).height(100%)} } 3.抽离嵌套组件ChildView 绑定双向监听。 Component export struct ChildView {private TAG: string TestPage;ObjectLink mTestInfo: TestInfobuild() {Column() {Text(this.mTestInfo.name).backgroundColor(Color.Red).fontSize(px2fp(52))ForEach(this.mTestInfo.items, (tempInfo: TestItem) {Text(tempInfo.content).fontSize(px2fp(52)).backgroundColor(tempInfo.isClicked ? Color.Blue : Color.Yellow).onClick(() {tempInfo.isClicked !tempInfo.isClickedconsole.log(this.TAG, JSON.stringify(tempInfo))})})Divider()}} } 渲染界面后的效果为 此时我们点击单元数据1或者2去修改isClicked选中状态并不会刷新UI整个代码有以上总结的三个问题 1.TestItem 多级嵌套嵌套对象的类并没有添加Observed进行监听 2.ChildView 多级嵌套了一个层级直接就进行了循环渲染其嵌套对象的View组件没有抽离出来添加ObjectLink进行该级对象的监听绑定 3.mTestDataArr嵌套对象中的TestItem并没有new出来创建是通过花括号直接赋值没有创建对象的过程无法激活Observed监听 三、完整DEMO示例 interface TestInfoInterFace {name: string;items: TestItem[]; }// TODO 问题1多层级时需要逐个层级进行类监听 Observed class TestItem {content: string ;isClicked: boolean false;constructor(content: string, isClicked: boolean) {this.content content;this.isClicked isClicked;} }Observed class TestInfo {name: string;items: TestItem[];constructor(name: string, items: TestItem[]) {this.name name;this.items items;} }Entry Component struct TestPage {// TODO 问题3 每个被设置Observed的对象需要new出来创建才能激活监听花括号的形式赋值并不会激活监听。State mTestDataArr: TestInfo[] [new TestInfo(测试数据1, [new TestItem(单元数据1, false), new TestItem(单元数据2, false)]),new TestInfo(测试数据2, [new TestItem(单元数据1, false), new TestItem(单元数据2, false)]),new TestInfo(测试数据3, [new TestItem(单元数据1, false), new TestItem(单元数据2, false)]),// new TestInfo(测试数据1, [{// content: 单元数据1,// isClicked: false// }, {// content: 单元数据1,// isClicked: false// }]),// new TestInfo(测试数据2, [{// content: 单元数据1,// isClicked: false// }, {// content: 单元数据1,// isClicked: false// }]),// new TestInfo(测试数据3, [{// content: 单元数据1,// isClicked: false// }, {// content: 单元数据1,// isClicked: false// }]),]build() {Column() {ForEach(this.mTestDataArr, (item: TestInfoInterFace) {ChildView({mTestInfo: item})})}.width(100%).height(100%)} }Component export struct ChildView {private TAG: string TestPage;ObjectLink mTestInfo: TestInfobuild() {Column() {Text(this.mTestInfo.name).backgroundColor(Color.Red).fontSize(px2fp(52))// TODO 多层级时需要逐个层级进行剥离创建子组件和绑定双向监听。// ForEach(this.mTestInfo.items, (tempInfo: TestItem) {// Text(tempInfo.content)// .fontSize(px2fp(52))// .backgroundColor(tempInfo.isClicked ? Color.Blue : Color.Yellow)// .onClick(() {// tempInfo.isClicked !tempInfo.isClicked// console.log(this.TAG, JSON.stringify(tempInfo))// })// })ForEach(this.mTestInfo.items, (tempInfo: TestItem) {ItemView({mItem: tempInfo}).margin({top: px2vp(100)})})Divider()}} }Component export struct ItemView {private TAG: string TestPage;ObjectLink mItem: TestItembuild() {Text(this.mItem.content).fontSize(px2fp(52)).backgroundColor(this.mItem.isClicked ? Color.Blue : Color.Yellow).onClick(() {this.mItem.isClicked !this.mItem.isClickedconsole.log(this.TAG, JSON.stringify(this.mItem))})} }
http://www.tj-hxxt.cn/news/223049.html

相关文章:

  • 电商数据网站如何下载js做的网站
  • 网站建设公司广告词大邯郸网站
  • 内蒙古网站建设网页版微信二维码不出来
  • 网站分为哪几个部分外包 网站开发公司
  • 彩票黑网站是怎么做的公司做网站需要准备什么条件
  • ps网站怎么做超链接做网站要学什么语言
  • 丰和园林建设集团网站wordpress熊掌号插件
  • 深圳如何搭建制作网站昆明网站建设建站模板
  • 乐陵人力资源网站学校网站代码模板
  • 好单库网站是怎么做的镇江关键词优化如何
  • 网站首页设计大赛国外网站建设软件
  • 网站提示域名重定向怎么做旅游网站名字
  • html基础网站建设优化seo
  • 网页设计作业 个人网站wordpress 个人站
  • 做外贸去哪些网站找老外人人商城源码
  • 爱空间网站模板wordpress模板制作软件
  • 青岛网站制作公司排名重庆喷绘制作
  • 成都网站开发外包网站建设 服务流程
  • 营销策划好的网站苏州seo优化公司
  • 做微商好还是开网站好没有网站可以做cpa
  • 长安做英文网站企业服务公司是干嘛的
  • 建设网站公司怎样的网站打开速度块
  • 青岛做网站哪家专业设计师 网站 贵
  • 专门做运动装备的网站做网站去哪里找广告主
  • 如何做网站的源码绍兴百度seo公司
  • 贵港公司做网站仙居做网站的
  • 张家港建网站价格南宁seo域名
  • qq整人网站怎么做医药网站开发
  • 网上做翻译兼职网站智慧校园学生端登录平台
  • 网页设计入门+齿轮站内seo内容优化包括