• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022-2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 // test the parser period of Repeat
16@Entry
17@ComponentV2
18struct Demo {
19  @Require @Param props;
20  @Local arr:string[] = [];
21  aboutToAppear(): void {
22    for(let i = 0; i < 100; i++) {
23      this.arr.push(i.toString())
24    }
25  }
26  build() {
27    Column() {
28      Button("test")
29        .onClick(()=>{
30          this.arr[20] = this.arr[20] + 'a';
31          this.arr[21] = this.arr[21] + 'a';
32        })
33      List() {
34        Repeat(this.arr)
35          .each((item)=>{
36            ListItem() {
37              Text(item.item)
38            }
39          })
40          .virtualScroll()
41      }
42      .cachedCount(1)
43      .height('30%')
44    }
45  }
46}
47
48@ComponentV2
49struct RepeatDemo {
50  @Local arr: string[] = ['1', '2', '3'];
51  build() {
52    Column() {
53      List() {
54        Repeat(this.arr)
55          .each((item)=>{})
56          .templateId(()=>{return 'temp'})
57          .template((()=>{return 'temp'})(), (item)=>{
58            ListItem() {
59              Text(item.item)
60            }
61          })
62      }
63    }
64  }
65}