我需要获取每个步骤的每个文本以及所属的文本。这是我的HTML(包括我的JavaScript):
<html>
<body>
<div id="art-title-boxes"></div>
<script>
var divContain = document.getElementById("art-title-boxes");
fetch('article-template.json')
.then(function (response) {
return response.json();
})
.then(function (data) {
addCatData(data);
});
function addCatData(data) {
for (var i = 0; i < data.length; i++) {
var div = document.createElement("div");
div.className = "art-name-box";
div.innerHTML = data[i].cnct-a.step;
divContain.appendChild(div);
var div2 = document.createElement("div");
div.innerHTML = data[i].cnct-a.text;
divContain.appendChild(div);
}}
</script>
</body>
</html>
我的JavaScript代码基于本文:https://howtocreateapps.com/fetch-and-display-json-html-javascript/ 这是我的.JSON文件的内容:
{
"cnct-a": [
{
"step": "1",
"text": "XXX"
},
{
"step": "2",
"text": "XXX"
},
{
"step": "3",
"text": "XXX"
}
],
"cnct-b": [
{
"step": "1",
"text": "XXX"
},
{
"step": "2",
"text": "XXX"
},
{
"step": "3",
"text": "XXX"
}
]
}
谢谢!