回答編集履歴

1

React の場合を追加

2018/05/18 17:44

投稿

og24715
og24715

スコア832

test CHANGED
@@ -1,3 +1,55 @@
1
1
  こんな感じでどうでしょう
2
2
 
3
3
  [https://codepen.io/og24715/pen/vjvypL?editors=1010](https://codepen.io/og24715/pen/vjvypL?editors=1010)
4
+
5
+
6
+
7
+
8
+
9
+ あー React 使えるなら次のように書けますね。
10
+
11
+
12
+
13
+ ```js
14
+
15
+
16
+
17
+ render() {
18
+
19
+ // 仮に textList という テキストの配列があったとして
20
+
21
+ const textList = ['This is a card', 'This is a card', 'This is a card', 'This is a card', 'This is a card', 'This is a card', 'This is a card', 'This is a card', 'This is a card', 'This is a card'];
22
+
23
+ // 本来なら private メソッドに隠蔽するか、Item コンポーネントとして切り出すべき
24
+
25
+ const renderitem = (text) => (
26
+
27
+ <div>
28
+
29
+ <img src="http://placehold.jp/150x150.png">
30
+
31
+ <p>{text}</p>
32
+
33
+ </div>
34
+
35
+ );
36
+
37
+ return (
38
+
39
+ <div>
40
+
41
+ {...textList.map(renderitem)}
42
+
43
+ </div>
44
+
45
+ );
46
+
47
+ }
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+ ```