我正在尝试使用对象对我的数组进行字符串化,但是当我这样做时,只会对数组中的第一个对象进行字符串化。
.container {
width: 430px;
background: grey;
overflow-x: scroll;
display: grid;
}
.container.container-wide{
width: 1000px;
}
.row {
display: grid;
grid-template-columns: minmax(200px, 1fr) minmax(200px, 1fr) minmax(200px, 1fr) minmax(100px, 1fr);
background: red;
height: 3rem;
}
.cell {
border: 1px solid black;
}
第一个Scroll to the right inside the box:
<div class="container">
<div class="row">
<span class="cell">cell 1</span>
<span class="cell">cell 2</span>
<span class="cell">cell 3</span>
<span class="cell">cell 4</span>
</div>
<div class="row">
<span class="cell">cell 1</span>
<span class="cell">cell 2</span>
<span class="cell">cell 3</span>
<span class="cell">cell 4</span>
</div>
</div>
Wide container:
<div class="container container-wide">
<div class="row">
<span class="cell">cell 1</span>
<span class="cell">cell 2</span>
<span class="cell">cell 3</span>
<span class="cell">cell 4</span>
</div>
<div class="row">
<span class="cell">cell 1</span>
<span class="cell">cell 2</span>
<span class="cell">cell 3</span>
<span class="cell">cell 4</span>
</div>
</div>
The red background should cover the whole row.
返回预期的以下内容:
first console.log
但是当它控制台记录字符串化的JSON时,我只会得到generatedJSON = [];
generatedJSON.push({code: codeName.value});
selectedTracks.forEach(track => {
fetch("some.api&data=" + track)
.catch(error => console.log(error)).then(function (response) {
if (response.status !== 200) {
console.log('Looks like there was a problem. Status Code: ' + response.status);
return;
}
response.json().then(data => {
let info = {
uri: "https://www.youtube.com/watch?v=" + data.items[0].id.videoId,
title: data.items[0].snippet.title,
description: data.items[0].snippet.description,
channel: data.items[0].snippet.channelTitle,
thumbnail: data.items[0].snippet.thumbnails.default.url,
publishedAt: data.items[0].snippet.publishedAt
};
generatedJSON.push(info);
});
})
});
console.log(generatedJSON);
console.log(JSON.stringify(generatedJSON));
second console.log
这很可能是菜鸟的错误,但是有人知道这里可能有什么问题吗?预先感谢