Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
41174e8c
D
Docs
项目概览
OpenHarmony
/
Docs
大约 2 年 前同步成功
通知
161
Star
293
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
41174e8c
编写于
8月 31, 2023
作者:
O
openharmony_ci
提交者:
Gitee
8月 31, 2023
浏览文件
操作
浏览文件
下载
差异文件
!23612 arkts 告警清理
Merge pull request !23612 from 耿文广/master
上级
2d2b5c71
3aa70bbd
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
46 addition
and
34 deletion
+46
-34
zh-cn/application-dev/quick-start/arkts-rendering-control-foreach.md
...cation-dev/quick-start/arkts-rendering-control-foreach.md
+38
-26
zh-cn/application-dev/quick-start/arkts-rendering-control-lazyforeach.md
...on-dev/quick-start/arkts-rendering-control-lazyforeach.md
+8
-8
未找到文件。
zh-cn/application-dev/quick-start/arkts-rendering-control-foreach.md
浏览文件 @
41174e8c
...
@@ -12,9 +12,9 @@ ForEach基于数组类型数据执行循环渲染。
...
@@ -12,9 +12,9 @@ ForEach基于数组类型数据执行循环渲染。
```
ts
```
ts
ForEach
(
ForEach
(
arr
:
any
[],
arr
:
Array
,
itemGenerator
:
(
item
:
an
y
,
index
?:
number
)
=>
void
,
itemGenerator
:
(
item
:
Arra
y
,
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
,
ind
x
)
=>
{
(
it
:
number
,
inde
x
)
=>
{
Text
(
`Item:
${
indx
}
-
${
it
}
`
)
Text
(
`Item:
${
ind
e
x
}
-
${
it
}
`
)
},
},
(
it
,
ind
x
)
=>
{
(
it
:
number
,
inde
x
)
=>
{
return
`
${
indx
}
-
${
it
}
`
return
`
${
ind
e
x
}
-
${
it
}
`
}
}
)
)
}
}
...
...
zh-cn/application-dev/quick-start/arkts-rendering-control-lazyforeach.md
浏览文件 @
41174e8c
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录