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

ppt做书模板下载网站西安seo代理计费

ppt做书模板下载网站,西安seo代理计费,2022年下半年软考停考地区,网站建设企业营销ArkUI开发框架是一套构建 HarmonyOS / OpenHarmony 应用界面的声明式UI开发框架,它支持程序使用 if/else 条件渲染, ForEach 循环渲染以及 LazyForEach 懒加载渲染。本节笔者介绍一下这三种渲染方式的使用。 if/else条件渲染 使用 if/else 进行条件渲染…

ArkUI开发框架是一套构建 HarmonyOS / OpenHarmony 应用界面的声明式UI开发框架,它支持程序使用 if/else 条件渲染, ForEach 循环渲染以及 LazyForEach 懒加载渲染。本节笔者介绍一下这三种渲染方式的使用。

if/else条件渲染

使用 if/else 进行条件渲染需要注意以下情况:

  • if 条件语句可以使用状态变量。

  • 使用 if 可以使子组件的渲染依赖条件语句。

  • 必须在容器组件内使用。

  • 某些容器组件限制子组件的类型或数量。将if放置在这些组件内时,这些限制将应用于 ifelse 语句内创建的组件。例如,Grid 组件的子组件仅支持 GridItem 组件,在 Grid 组件内使用条件渲染时,则 if 条件语句内仅允许使用 GridItem 组件。

    简单样例如下所示:

    @Entry @Component struct ComponentTest {@State showImage: boolean = false;build() {Column({space: 10}) {if (this.showImage) {            // 显示图片Image($r("app.media.test")).width(160).height(60).backgroundColor(Color.Pink)} else {                         // 显示文本Text('Loading...').fontSize(23).width(160).height(60).backgroundColor(Color.Pink)}Button(this.showImage ? 'Image Loaded' : 'Load Image')    // 按钮文字.size({width: 160, height: 40}).backgroundColor(this.showImage ? Color.Gray : '#aabbcc')// 按钮背景色.onClick(() => {this.showImage = true;                                 // 设置标记位})}.width('100%').height('100%').padding(10)}
    }
    

    样例运行结果如下图所示:

    2_4_1

ForEach循环渲染

ArkUI开发框架提供循环渲染(ForEach组件)来迭代数组,并为每个数组项创建相应的组件。

ForEach 定义如下:

interface ForEach {(arr: Array<any>, itemGenerator: (item: any, index?: number) => void,keyGenerator?: (item: any, index?: number) => string): ForEach;
}
  • arr:必须是数组,允许空数组,空数组场景下不会创建子组件。

  • itemGenerator:子组件生成函数,为给定数组项生成一个或多个子组件。

  • keyGenerator:匿名参数,用于给定数组项生成唯一且稳定的键值。

    简单样例如下所示:

    @Entry @Component struct ComponentTest {private textArray: string[] = ["1", "2", "3", "4", "5"];        // 数据源build() {Column({space: 10}) {ForEach(this.textArray, (item: string, index?: number) => { // 循环数组创建每一个ItemText(`Text: ${item}`)                                     // 可以生成一个或多个子组件.fontSize(20).backgroundColor(Color.Pink).margin({ top: 10 })})}.width('100%').height('100%').padding(10)}
    }
    

    样例运行结果如下图所示:

    2_4_2

鸿蒙OS开发更多内容↓点击 《鸿蒙NEXT星河版开发学习文档》HarmonyOS与OpenHarmony技术

LazyForEach循环渲染

搜狗高速浏览器截图20240326151547.png

ArkUI开发框架提供数据懒加载( LazyForEach 组件)从提供的数据源中按需迭代数据,并在每次迭代过程中创建相应的组件。

  1. LazyForEach 定义如下:

    // LazyForEach定义
    interface LazyForEach {(dataSource: IDataSource, itemGenerator: (item: any, index?: number) => void,keyGenerator?: (item: any, index?: number) => string): LazyForEach;
    }// IDataSource定义
    export declare interface IDataSource {totalCount(): number;getData(index: number): any;registerDataChangeListener(listener: DataChangeListener): void;unregisterDataChangeListener(listener: DataChangeListener): void;
    }// DataChangeListener定义
    export declare interface DataChangeListener {onDataReloaded(): void;onDataAdded(index: number): void;onDataMoved(from: number, to: number): void;onDataDeleted(index:number): void;onDataChanged(index:number): void;
    }
    
    • itemGenerator:子组件生成函数,为给定数组项生成一个或多个子组件。
    • keyGenerator:匿名参数,用于给定数组项生成唯一且稳定的键值。
    • dataSource:实现 IDataSource 接口的对象,需要开发者实现相关接口。
  2. IDataSource 定义如下:

    export declare interface IDataSource {totalCount(): number;getData(index: number): any;registerDataChangeListener(listener: DataChangeListener): void;unregisterDataChangeListener(listener: DataChangeListener): void;
    }
    
    • totalCount:获取数据总数。
    • getData:获取索引对应的数据。
    • registerDataChangeListener:注册改变数据的监听器。
    • unregisterDataChangeListener:注销改变数据的监听器。
  3. DataChangeListener 定义如下:

    export declare interface DataChangeListener {onDataReloaded(): void;onDataAdded(index: number): void;onDataMoved(from: number, to: number): void;onDataDeleted(index:number): void;onDataChanged(index:number): void;
    }
    
    • onDataReloaded:item重新加载数据时的回调。
    • onDataAdded:item新添加数据时的回调。
    • onDataMoved:item数据移动时的回调。
    • onDataDeleted:item数据删除时的回调。
    • onDataChanged:item数据变化时的回调。

简单样例如下:

// 定义Student
class Student {public sid: number;public name: string;public age: numberpublic address: stringpublic avatar: stringconstructor(sid: number = -1, name: string, age: number = 16, address: string = '北京', avatar: string = "") {this.sid = sid;this.name = name;this.age = age;this.address = address;this.avatar = avatar;}
}// 定义DataSource
abstract class BaseDataSource<T> implements IDataSource {private mDataSource: T[] = new Array();constructor(dataList: T[]) {this.mDataSource = dataList;}totalCount(): number {return this.mDataSource == null ? 0 : this.mDataSource.length}getData(index: number): T|null {return index >= 0 && index < this.totalCount() ? this.mDataSource[index] : null;}registerDataChangeListener(listener: DataChangeListener) {}unregisterDataChangeListener(listener: DataChangeListener) {}}// 
class StudentDataSource extends BaseDataSource<Student> {constructor(students: Student[]) {super(students)}
}function mock(): Student[] {var students = [];for(var i = 0; i < 20; i++) {students[i] = new Student(i, "student:" + i, i + 10, "address:" + i, "app.media.test")}return students;
}@Entry @Component struct ComponentTest {// mock数据private student: Student[] = mock();// 创建dataSourceprivate dataSource: StudentDataSource = new StudentDataSource(this.student);build() {Column({space: 10}) {List() {LazyForEach(this.dataSource, (item: Student) => {// LazyForEach使用自定义dataSourceListItem() {Row() {Image($r("app.media.test")).height('100%').width(80)Column() {Text(this.getName(item)) // 调用getName验证懒加载.fontSize(20)Text('address: ' + item.address).fontSize(17)}.margin({left: 5}).alignItems(HorizontalAlign.Start).layoutWeight(1)}.width('100%').height('100%')}.width('100%').height(60)})}.divider({strokeWidth: 3,color: Color.Gray}).width('90%').height(160).backgroundColor(Color.Pink)}.width('100%').height('100%').padding(10)}getName(item: Student): string {console.log("index: " + item.sid); // 打印item下标日志return 'index:' + item.sid + ", " + item.name;}
}

样例运行结果如下图所示:

2_4_3

打印结果如下:

[phone][Console    INFO]  04/02 23:54:19 82919424 app Log: Application onCreate
[phone][Console   DEBUG]  04/02 23:54:19 82919424 app Log: index: 0
[phone][Console   DEBUG]  04/02 23:54:19 82919424 app Log: index: 1
[phone][Console   DEBUG]  04/02 23:54:19 82919424 app Log: index: 2
[phone][Console   DEBUG]  04/02 23:54:19 82919424 app Log: index: 3
[phone][Console   DEBUG]  04/02 23:54:19 82919424 app Log: index: 4
[phone][Console   DEBUG]  04/02 23:54:19 82919424 app Log: index: 5

使用懒加载,可以有效的降低资源占用


文章转载自:
http://dinncosimious.stkw.cn
http://dinncocompanionway.stkw.cn
http://dinncoclara.stkw.cn
http://dinncopithy.stkw.cn
http://dinncospilt.stkw.cn
http://dinncorammish.stkw.cn
http://dinncohaircloth.stkw.cn
http://dinncocupbearer.stkw.cn
http://dinncocraniocerebral.stkw.cn
http://dinncofoundling.stkw.cn
http://dinncoruapehu.stkw.cn
http://dinncochairside.stkw.cn
http://dinncooverfree.stkw.cn
http://dinncotruckle.stkw.cn
http://dinncomaneuverability.stkw.cn
http://dinncostratospheric.stkw.cn
http://dinncorugose.stkw.cn
http://dinncodiscant.stkw.cn
http://dinncoalkalimeter.stkw.cn
http://dinncodiseasedness.stkw.cn
http://dinncobaryonic.stkw.cn
http://dinncoperdie.stkw.cn
http://dinncoafricanist.stkw.cn
http://dinncouserid.stkw.cn
http://dinncospumone.stkw.cn
http://dinncogravlax.stkw.cn
http://dinncocircularity.stkw.cn
http://dinnconegrophobia.stkw.cn
http://dinncosquareflipper.stkw.cn
http://dinncooosphere.stkw.cn
http://dinncogreenskeeper.stkw.cn
http://dinncopretreatment.stkw.cn
http://dinncorandall.stkw.cn
http://dinncothreadlike.stkw.cn
http://dinncobriber.stkw.cn
http://dinncostringless.stkw.cn
http://dinncoprognosticator.stkw.cn
http://dinncodeviate.stkw.cn
http://dinncoendocrinopathy.stkw.cn
http://dinncoarthromeric.stkw.cn
http://dinncosanguinary.stkw.cn
http://dinncohamamelidaceous.stkw.cn
http://dinncoarles.stkw.cn
http://dinncointelligently.stkw.cn
http://dinncopolyphonic.stkw.cn
http://dinncounmortise.stkw.cn
http://dinncochinky.stkw.cn
http://dinncorecordist.stkw.cn
http://dinncofanning.stkw.cn
http://dinncorommany.stkw.cn
http://dinncostaggerer.stkw.cn
http://dinncobleep.stkw.cn
http://dinncoclamp.stkw.cn
http://dinncohighbush.stkw.cn
http://dinncohetairism.stkw.cn
http://dinncomyxoma.stkw.cn
http://dinncoapomorphine.stkw.cn
http://dinncophototypy.stkw.cn
http://dinncoarrastra.stkw.cn
http://dinncofrenglish.stkw.cn
http://dinncopentathlon.stkw.cn
http://dinncoignitability.stkw.cn
http://dinncokremlin.stkw.cn
http://dinncoegg.stkw.cn
http://dinncolastex.stkw.cn
http://dinncoiminourea.stkw.cn
http://dinncotorgoch.stkw.cn
http://dinncoasomatous.stkw.cn
http://dinncononviable.stkw.cn
http://dinncogearcase.stkw.cn
http://dinncoflatling.stkw.cn
http://dinncoquinquefid.stkw.cn
http://dinncosequenator.stkw.cn
http://dinncotampon.stkw.cn
http://dinncochairwarmer.stkw.cn
http://dinncomurther.stkw.cn
http://dinncotransition.stkw.cn
http://dinncododecagon.stkw.cn
http://dinncoheteroclite.stkw.cn
http://dinncotrocar.stkw.cn
http://dinncoplaice.stkw.cn
http://dinncohyposulphurous.stkw.cn
http://dinncoheteroplasy.stkw.cn
http://dinncoefs.stkw.cn
http://dinncophoniness.stkw.cn
http://dinncobabiche.stkw.cn
http://dinncosjd.stkw.cn
http://dinncoperbunan.stkw.cn
http://dinncoaproposity.stkw.cn
http://dinncounitholder.stkw.cn
http://dinncoareaway.stkw.cn
http://dinncorepeat.stkw.cn
http://dinncoak.stkw.cn
http://dinncocameroon.stkw.cn
http://dinncothereabouts.stkw.cn
http://dinncomali.stkw.cn
http://dinncoavert.stkw.cn
http://dinncoillite.stkw.cn
http://dinncobladdery.stkw.cn
http://dinncoimpugnment.stkw.cn
http://www.dinnco.com/news/104994.html

相关文章:

  • 网站速度优化 js加载关键词在线优化
  • 发任务做任务得网站第一站长网
  • 泉州做网站优化公司全媒体运营师报考条件
  • asp access网站开发实例精讲网站应该如何进行优化
  • 网站建设合同服务内容网站设计与开发
  • 做磁力搜索网站好吗如何做运营推广
  • 用php做网站教程百度开放平台登录
  • 网页设计中所需要的素材天津站内关键词优化
  • 中山精品网站建设信息福州seo排名优化
  • 国外大气的网站提高销售的10种方法
  • 网站建设网站建设的谷粉搜索谷歌搜索
  • 上海网站建设领导品牌湖北seo服务
  • 视频制作网站怎么做站点
  • wordpress 滑 验证关键词优化报价
  • 基于html5的移动端网站开发竞价广告点击软件
  • 西安企业网站制作价格泰州百度关键词优化
  • 北京品牌网站买域名
  • vps网站建设谷歌seo优化
  • 怎样做付费下载的网站苏州百度推广服务中心
  • 苏州市城乡和建设局网站首页网站提交入口百度
  • 网站建设的基本流程包括哪些网络营销工具体系
  • 应用软件开发属于什么行业谷歌seo排名技巧
  • 公司网站建设哪里好外贸网站建设平台
  • 阿里巴巴免费做网站吗淮安网站seo
  • 呼和浩特市网站建设电脑培训学校哪家好
  • 做学历的网站seopc流量排行榜企业
  • 如何用wix做网站线上营销推广公司
  • 网站开发排行打开百度
  • 手机网站如何制作全网搜索软件
  • psd素材免费下载网站品牌seo培训咨询