ForEach:循环渲染
官方:ForEach接口基于数组类型数据来进行循环渲染,需要与容器组件配合使用,且接口返回的组件应当是允许包含在ForEach父容器组件中的子组件。
语法:
ForEach(
arr: Array,
itemGenerator: (item: any, index?: number) => void,
keyGenerator?: (item: any, index?: number) => string
)
参数解释:
1、arr: Array 要遍历的数据,数组
2、itemGenerator: (item: any, index?: number) => void,
itemGenerator: (item: any, index?: number) => {},
组件生成函数(数组中的数据项,数组中的数据项索引-可省略)
返回函数或void
3、 keyGenerator?: (item: any, index?: number) => string
可省略,键值生成函数(数组中的数据项,数组中的数据项索引-可省略)
如果函数缺省,框架默认的键值生成函数为(item: T, index: number) => { return index + ‘__’ + JSON.stringify(item); }
示例1:
@State simpleList: Array<string> = ['one', 'two', 'three'];
ForEach(this.simpleList, (item2: string) => {
Text(item2).fontColor(Color.Red)

4577

被折叠的 条评论
为什么被折叠?



