在此流程中如何从“money_line”获取“Home”和“Away”的值。
"periods": {
"num_0": {
"money_line": {
"home": 1.448,
"draw": null,
"away": 2.92
},
},
}
const obj = JSON.parse(this.responseText);
Array.from(home_team).forEach((home, index) => {
home.innerText = obj.events[index].home;
});
我们没有足够的信息来弄清楚您想要实现的目标。
看起来你有一个类似数组的对象
home_team
,其中包含HTMLElement
。您正在从 XHR 接收 JSON 字符串并解析它。然后迭代 home_team
中的每个项目,将其 innerText 设置为解析的 JSON 字符串中的值...
基于此,我假设您需要以下内容:
const obj = JSON.parse(this.responseText);
Array.from(money_line).forEach((line, index) => {
const num = `num_${index}`;
const team = ['home', 'away'][index];
line.innerText = obj.periods[num].money_line[team];
});
我保留的代码与您已经使用的代码类似。如果您可以提供有关其他变量、表结构和请求结构的更多信息,我将相应地更新我的答案。