1 回答
TA贡献2011条经验 获得超2个赞
一个可能的解决方案是创建一个包含问题对象列表的 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": "";
}
]
然后获取数据,并使用 foreach 循环创建一个构造函数并将每个构造函数附加到任务列表中
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)
})
}
如果由于我使用平板电脑打字而出现语法错误,请原谅我的代码
添加回答
举报