回答編集履歴
2
追記
test
CHANGED
@@ -63,3 +63,135 @@
|
|
63
63
|
</div>
|
64
64
|
|
65
65
|
```
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
---
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
例えばこんな感じでしょうか。(タグは適当です。)
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
```jsx
|
78
|
+
|
79
|
+
function App() {
|
80
|
+
|
81
|
+
const data = [
|
82
|
+
|
83
|
+
{
|
84
|
+
|
85
|
+
"id": "1",
|
86
|
+
|
87
|
+
"contents": [
|
88
|
+
|
89
|
+
{
|
90
|
+
|
91
|
+
"type": "definition",
|
92
|
+
|
93
|
+
"content": "題名1"
|
94
|
+
|
95
|
+
},
|
96
|
+
|
97
|
+
{
|
98
|
+
|
99
|
+
"type": "image",
|
100
|
+
|
101
|
+
"content": "hoge1.jpg"
|
102
|
+
|
103
|
+
},
|
104
|
+
|
105
|
+
{
|
106
|
+
|
107
|
+
"type": "text",
|
108
|
+
|
109
|
+
"content": "テキスト"
|
110
|
+
|
111
|
+
},
|
112
|
+
|
113
|
+
{
|
114
|
+
|
115
|
+
"type": "image",
|
116
|
+
|
117
|
+
"content": "hoge2.jpg"
|
118
|
+
|
119
|
+
}
|
120
|
+
|
121
|
+
],
|
122
|
+
|
123
|
+
"images": [
|
124
|
+
|
125
|
+
{
|
126
|
+
|
127
|
+
"src": "hoge1.jpg",
|
128
|
+
|
129
|
+
"imageUrl": "https://xxx/hoge1.jpg"
|
130
|
+
|
131
|
+
},
|
132
|
+
|
133
|
+
{
|
134
|
+
|
135
|
+
"src": "hoge2.jpg",
|
136
|
+
|
137
|
+
"imageUrl": "https://xxx/hoge2.jpg"
|
138
|
+
|
139
|
+
}
|
140
|
+
|
141
|
+
]
|
142
|
+
|
143
|
+
}
|
144
|
+
|
145
|
+
];
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
const findImageUrl = (images, content) => {
|
150
|
+
|
151
|
+
return images.find(image => image.src == content).imageUrl;
|
152
|
+
|
153
|
+
};
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
return (
|
158
|
+
|
159
|
+
<div>
|
160
|
+
|
161
|
+
{data.map(item => (
|
162
|
+
|
163
|
+
<div key={item.id}>
|
164
|
+
|
165
|
+
{item.contents.map(({ type, content }) => {
|
166
|
+
|
167
|
+
switch (type) {
|
168
|
+
|
169
|
+
case "definition":
|
170
|
+
|
171
|
+
return <h1>{content}</h1>;
|
172
|
+
|
173
|
+
case "text":
|
174
|
+
|
175
|
+
return <p>{content}</p>;
|
176
|
+
|
177
|
+
case "image":
|
178
|
+
|
179
|
+
const imageUrl = findImageUrl(item.images, content);
|
180
|
+
|
181
|
+
return <Image src={imageUrl} width="100" height="100" />;
|
182
|
+
|
183
|
+
}
|
184
|
+
|
185
|
+
})}
|
186
|
+
|
187
|
+
</div>
|
188
|
+
|
189
|
+
))}
|
190
|
+
|
191
|
+
</div>
|
192
|
+
|
193
|
+
);
|
194
|
+
|
195
|
+
}
|
196
|
+
|
197
|
+
```
|
1
追記
test
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
>
|
1
|
+
> 複数ある場合は全部表示させたいです。
|
2
2
|
|
3
3
|
> 0個の場合は、何も表示させません。
|
4
4
|
|
@@ -21,3 +21,45 @@
|
|
21
21
|
</div>
|
22
22
|
|
23
23
|
```
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
---
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
> 意図している表示は↓
|
32
|
+
|
33
|
+
> テキスト
|
34
|
+
|
35
|
+
> 画像1
|
36
|
+
|
37
|
+
> テキスト
|
38
|
+
|
39
|
+
> 画像2
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
ということなら map の中にテキストを入れれば良いでしょう。
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
```jsx
|
48
|
+
|
49
|
+
<div>
|
50
|
+
|
51
|
+
{content.images.map((image, index) => (
|
52
|
+
|
53
|
+
<div key={index}>
|
54
|
+
|
55
|
+
<p>テキスト</p>
|
56
|
+
|
57
|
+
<Image src={image.imageUrl} width="100" height="100" />
|
58
|
+
|
59
|
+
</div>
|
60
|
+
|
61
|
+
))}
|
62
|
+
|
63
|
+
</div>
|
64
|
+
|
65
|
+
```
|