未验证 提交 02092d93 编写于 作者: 耿文广 提交者: Gitee

update zh-cn/application-dev/quick-start/arkts-rendering-control-lazyforeach.md.

Signed-off-by: N耿文广 <gengwenguang@huawei.com>
上级 7c11d55f
......@@ -9,22 +9,22 @@ LazyForEach从提供的数据源中按需迭代数据,并在每次迭代过程
```ts
LazyForEach(
dataSource: IDataSource, // 需要进行数据迭代的数据源
itemGenerator: (item: any) => void, // 子组件生成函数
keyGenerator?: (item: any) => string // (可选) .键值生成函数
dataSource: IDataSource, // Data source to iterate over
itemGenerator: (item: Object) => void, // Child component generation function
keyGenerator?: (item: Object): string => string // (Optional). ID generation function
): void
interface IDataSource {
totalCount(): number; // 获得数据总数
getData(index: number): any; // 获取索引值对应的数据
registerDataChangeListener(listener: DataChangeListener): void; // 注册数据改变的监听器
unregisterDataChangeListener(listener: DataChangeListener): void; // 注销数据改变的监听器
totalCount(): number; // Get total count of data
getData(index: number): any; // Get single data by index
registerDataChangeListener(listener: DataChangeListener): void; // Register listener to listening data changes
unregisterDataChangeListener(listener: DataChangeListener): void; // Unregister listener
}
interface DataChangeListener {
onDataReloaded(): void; // 重新加载数据时调用
onDataAdd(index: number): void; // 添加数据时调用
onDataMove(from: number, to: number): void; // 数据移动起始位置与数据移动目标位置交换时调用
onDataDelete(index: number): void; // 删除数据时调用
onDataChange(index: number): void; // 改变数据时调用
onDataReloaded(): void; // Called while data reloaded
onDataAdd(index: number): void; // Called while single data added
onDataMove(from: number, to: number): void; // Called while single data moved
onDataDelete(index: number): void; // Called while single data deleted
onDataChange(index: number): void; // Called while single data changed
}
```
......@@ -44,7 +44,7 @@ interface DataChangeListener {
```ts
interface IDataSource {
totalCount(): number;
getData(index: number): any;
getData(index: number): Object;
registerDataChangeListener(listener: DataChangeListener): void;
unregisterDataChangeListener(listener: DataChangeListener): void;
}
......@@ -109,8 +109,8 @@ interface DataChangeListener {
```ts
LazyForEach(dataSource,
item => Text(`${item.i}. item.data.label`),
item => item.data.id.toString())
(item: Object) => Text(`${item.i}. item.data.label`),
(item: Object): string => item.data.id.toString())
```
......@@ -126,7 +126,7 @@ class BasicDataSource implements IDataSource {
return 0;
}
public getData(index: number): any {
public getData(index: number): undefined {
return undefined;
}
......@@ -177,13 +177,13 @@ class BasicDataSource implements IDataSource {
}
class MyDataSource extends BasicDataSource {
private dataArray: string[] = [];
private dataArray: string[] = ['/path/image0', '/path/image1', '/path/image2', '/path/image3'];
public totalCount(): number {
return this.dataArray.length;
}
public getData(index: number): any {
public getData(index: number): Object {
return this.dataArray[index];
}
......@@ -201,12 +201,6 @@ class MyDataSource extends BasicDataSource {
@Entry
@Component
struct MyComponent {
aboutToAppear() {
for (var i = 100; i >= 80; i--) {
this.data.pushData(`Hello ${i}`)
}
}
private data: MyDataSource = new MyDataSource();
build() {
......@@ -214,17 +208,15 @@ struct MyComponent {
LazyForEach(this.data, (item: string) => {
ListItem() {
Row() {
Text(item).fontSize(50)
.onAppear(() => {
console.info("appear:" + item)
})
Image(item).width('30%').height(50)
Text(item).fontSize(20).margin({ left: 10 })
}.margin({ left: 10, right: 10 })
}
.onClick(() => {
this.data.pushData(`Hello ${this.data.totalCount()}`);
this.data.pushData('/path/image' + this.data.totalCount());
})
}, item => item)
}.cachedCount(5)
}, (item: string) => item)
}
}
}
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册