1 回答

TA貢獻(xiàn)2011條經(jīng)驗(yàn) 獲得超2個(gè)贊
一個(gè)可能的解決方案是創(chuàng)建一個(gè)包含問(wèn)題對(duì)象列表的 json 文件,如下所示
[
{
"question": "some question",
"answer": ["", "", "", "", ""];
"hint": ["", "", "", "", ""];
"icon": "fa-utensils-alt";
"image": "img/001.jpg";
"congrats": "That's right.... ";
"location": "";
},
{
"question": "some question",
"answer": ["", "", "", "", ""];
"hint": ["", "", "", "", ""];
"icon": "fa-utensils-alt";
"image": "img/001.jpg";
"congrats": "That's right.... ";
"location": "";
}
]
然后獲取數(shù)據(jù),并使用 foreach 循環(huán)創(chuàng)建一個(gè)構(gòu)造函數(shù)并將每個(gè)構(gòu)造函數(shù)附加到任務(wù)列表中
async function (fetchedJson) {
fetchedJson.forEach((item) => {
const que = new Question(
item.question,
item.answer,
item.hint,
item.icon,
item.image,
item.congrats,
item.location
)
quest.push(que)
})
}
如果由于我使用平板電腦打字而出現(xiàn)語(yǔ)法錯(cuò)誤,請(qǐng)?jiān)徫业拇a
添加回答
舉報(bào)