1 回答

TA貢獻2011條經(jīng)驗 獲得超2個贊
一個可能的解決方案是創(chuàng)建一個包含問題對象列表的 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)建一個構造函數(shù)并將每個構造函數(shù)附加到任務列表中
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)語法錯誤,請原諒我的代碼
添加回答
舉報