未验证 提交 41174e8c 编写于 作者: O openharmony_ci 提交者: Gitee

!23612 arkts 告警清理

Merge pull request !23612 from 耿文广/master
...@@ -12,9 +12,9 @@ ForEach基于数组类型数据执行循环渲染。 ...@@ -12,9 +12,9 @@ ForEach基于数组类型数据执行循环渲染。
```ts ```ts
ForEach( ForEach(
arr: any[], arr: Array,
itemGenerator: (item: any, index?: number) => void, itemGenerator: (item: Array, index?: number) => void,
keyGenerator?: (item: any, index?: number) => string keyGenerator?: (item: Array, index?: number): string => string
) )
``` ```
...@@ -37,9 +37,16 @@ ForEach( ...@@ -37,9 +37,16 @@ ForEach(
- itemGenerator函数的调用顺序不一定和数组中的数据项相同,在开发过程中不要假设itemGenerator和keyGenerator函数是否执行及其执行顺序。例如,以下示例可能无法正确运行: - itemGenerator函数的调用顺序不一定和数组中的数据项相同,在开发过程中不要假设itemGenerator和keyGenerator函数是否执行及其执行顺序。例如,以下示例可能无法正确运行:
```ts ```ts
ForEach(anArray.map((item1, index1) => { return { i: index1 + 1, data: item1 }; }), let obj: Object
item => Text(`${item.i}. item.data.label`), ForEach(anArray.map((item1: Object, index1: number): Object => {
item => item.data.id.toString()) obj.i = index1 + 1
obj.data = item1
return obj;
}),
(item: string) => Text(`${item.i}. item.data.label`),
(item: string): string => {
return item.data.id.toString()
})
``` ```
...@@ -90,7 +97,7 @@ struct MyComponent { ...@@ -90,7 +97,7 @@ struct MyComponent {
```ts ```ts
@Component @Component
struct CounterView { struct CounterView {
label: string; @State label: string = "";
@State count: number = 0; @State count: number = 0;
build() { build() {
...@@ -147,10 +154,10 @@ struct MainView { ...@@ -147,10 +154,10 @@ struct MainView {
}) })
.width(300).height(40) .width(300).height(40)
ForEach(this.arr, ForEach(this.arr,
(item) => { (item: string) => {
CounterView({ label: item.toString() }) CounterView({ label: item.toString() })
}, },
(item) => item.toString() (item: string) => item.toString()
) )
} }
} }
...@@ -175,9 +182,11 @@ MainView拥有一个\@State装饰的数字数组。添加、删除和替换数 ...@@ -175,9 +182,11 @@ MainView拥有一个\@State装饰的数字数组。添加、删除和替换数
如前所述,id生成函数是可选的。以下是不带项索引函数的ForEach: 如前所述,id生成函数是可选的。以下是不带项索引函数的ForEach:
```ts ```ts
ForEach(this.arr, let list: Object
(item) => { ForEach(this.arr,
CounterView({ label: item.toString() }) (item: Object): string => {
list.label = item.toString();
CounterView(list)
} }
) )
``` ```
...@@ -228,10 +237,10 @@ struct MainView { ...@@ -228,10 +237,10 @@ struct MainView {
build() { build() {
Column() { Column() {
ForEach(this.counters.slice(this.firstIndex, this.firstIndex + 3), ForEach(this.counters.slice(this.firstIndex, this.firstIndex + 3),
(item) => { (item: MyCounter) => {
CounterView({ label: `Counter item #${item.id}`, counter: item }) CounterView({ label: `Counter item #${item.id}`, counter: item })
}, },
(item) => item.id.toString() (item: MyCounter) => item.id.toString()
) )
Button(`Counters: shift up`) Button(`Counters: shift up`)
.width(200).height(50) .width(200).height(50)
...@@ -266,7 +275,7 @@ class Month { ...@@ -266,7 +275,7 @@ class Month {
month: number; month: number;
days: number[]; days: number[];
constructor(year: number, month: number, days: number[]) { constructor(year: number, month: number, ...days: number[]) {
this.year = year; this.year = year;
this.month = month; this.month = month;
this.days = days; this.days = days;
...@@ -275,13 +284,16 @@ class Month { ...@@ -275,13 +284,16 @@ class Month {
@Component @Component
struct CalendarExample { struct CalendarExample {
// 模拟6个月 // 模拟6个月
arr28: Array<number> = Array(31).fill(0).map((_: number, i: number): number => i + 1);
arr30: Array<number> = Array(31).fill(0).map((_: number, i: number): number => i + 1);
arr31: Array<number> = Array(31).fill(0).map((_: number, i: number): number => i + 1);
@State calendar : Month[] = [ @State calendar : Month[] = [
new Month(2020, 1, [...Array(31).keys()]), new Month(2020, 1, ...(this.arr31)),
new Month(2020, 2, [...Array(28).keys()]), new Month(2020, 2, ...(this.arr28)),
new Month(2020, 3, [...Array(31).keys()]), new Month(2020, 3, ...(this.arr31)),
new Month(2020, 4, [...Array(30).keys()]), new Month(2020, 4, ...(this.arr30)),
new Month(2020, 5, [...Array(31).keys()]), new Month(2020, 5, ...(this.arr31)),
new Month(2020, 6, [...Array(30).keys()]) new Month(2020, 6, ...(this.arr30))
] ]
build() { build() {
Column() { Column() {
...@@ -289,7 +301,7 @@ struct CalendarExample { ...@@ -289,7 +301,7 @@ struct CalendarExample {
Text('next month') Text('next month')
}.onClick(() => { }.onClick(() => {
this.calendar.shift() this.calendar.shift()
this.calendar.push(new Month(year: 2020, month: 7, days: [...Array(31).keys()])) this.calendar.push(new Month(2020, 7, ...(this.arr31)))
}) })
ForEach(this.calendar, ForEach(this.calendar,
(item: Month) => { (item: Month) => {
...@@ -330,11 +342,11 @@ struct ForEachWithIndex { ...@@ -330,11 +342,11 @@ struct ForEachWithIndex {
build() { build() {
Column() { Column() {
ForEach(this.arr, ForEach(this.arr,
(it, indx) => { (it: number, index) => {
Text(`Item: ${indx} - ${it}`) Text(`Item: ${index} - ${it}`)
}, },
(it, indx) => { (it: number, index) => {
return `${indx} - ${it}` return `${index} - ${it}`
} }
) )
} }
......
...@@ -9,9 +9,9 @@ LazyForEach从提供的数据源中按需迭代数据,并在每次迭代过程 ...@@ -9,9 +9,9 @@ LazyForEach从提供的数据源中按需迭代数据,并在每次迭代过程
```ts ```ts
LazyForEach( LazyForEach(
dataSource: IDataSource, // 需要进行数据迭代的数据源 dataSource: IDataSource, // 需要进行数据迭代的数据源
itemGenerator: (item: any) => void, // 子组件生成函数 itemGenerator: (item: Object) => void, // 需要进行数据迭代的数据源
keyGenerator?: (item: any) => string // (可选) .键值生成函数 keyGenerator?: (item: Object): string => string // 需要进行数据迭代的数据源
): void ): void
interface IDataSource { interface IDataSource {
totalCount(): number; // 获得数据总数 totalCount(): number; // 获得数据总数
...@@ -44,7 +44,7 @@ interface DataChangeListener { ...@@ -44,7 +44,7 @@ interface DataChangeListener {
```ts ```ts
interface IDataSource { interface IDataSource {
totalCount(): number; totalCount(): number;
getData(index: number): any; getData(index: number): Object;
registerDataChangeListener(listener: DataChangeListener): void; registerDataChangeListener(listener: DataChangeListener): void;
unregisterDataChangeListener(listener: DataChangeListener): void; unregisterDataChangeListener(listener: DataChangeListener): void;
} }
...@@ -109,8 +109,8 @@ interface DataChangeListener { ...@@ -109,8 +109,8 @@ interface DataChangeListener {
```ts ```ts
LazyForEach(dataSource, LazyForEach(dataSource,
item => Text(`${item.i}. item.data.label`), (item: Object) => Text(`${item.i}. item.data.label`),
item => item.data.id.toString()) (item: Object): string => item.data.id.toString())
``` ```
...@@ -126,7 +126,7 @@ class BasicDataSource implements IDataSource { ...@@ -126,7 +126,7 @@ class BasicDataSource implements IDataSource {
return 0; return 0;
} }
public getData(index: number): any { public getData(index: number): undefined {
return undefined; return undefined;
} }
...@@ -183,7 +183,7 @@ class MyDataSource extends BasicDataSource { ...@@ -183,7 +183,7 @@ class MyDataSource extends BasicDataSource {
return this.dataArray.length; return this.dataArray.length;
} }
public getData(index: number): any { public getData(index: number): Object {
return this.dataArray[index]; return this.dataArray[index];
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册