English 中文(简体)
为什么食宿
原标题:Why does loop doesn t loop JSON array
  • 时间:2023-07-13 02:55:51
  •  标签:
  • javascript

我有一份以色人种格式的运动员名单。 在使用假体时,我想 gr掉名册上的所有名字; at子和大体;名字,然后把它们插入倒塌的菜单。

但是,出于某种原因, lo不行。 如果我看一看一看一看一看一看一看一看一看一看一看一看一看一看一看一看一看一看一看一看一看一看一看一去。 难道我要混淆一下阵列和物体吗?

JSON代码

{
    "team": {
        "color": "000000",
        "country": "USA",
        "roster": [
            {
                "athlete": {
                    "name": "John Doe",
                    "age": 20
                }
            },
            {
                "athlete": {
                    "name": "Jane Doe",
                    "age": 21
                }
            },
            {
                "athlete": {
                    "name": "Jack Doe",
                    "age": 22
                }
            },
            {
                "athlete": {
                    "name": "Joe Doe",
                    "age": 23
                }
            }
        ]
    }
}

我有一份以色人种格式的运动员名单。 在使用假体时,我想 gr掉名册上的所有名字; at子和大体;名字,然后把它们插入倒塌的菜单。

但是,出于某种原因, lo不行。 如果我看一看一看一看一看一看一看一看一看一看一看一看一看一看一看一看一看一看一看一看一看一看一看一去。 难道我要混淆一下阵列和物体吗?

JSON代码

{ "team": { "color": "000000", "country": "USA", "roster": [ { "athlete": { "name": "John Doe", "age": 20 } }, { "athlete": { "name": "Jane Doe", "age": 21 } }, { "athlete": { "name": "Jack Doe", "age": 22 } }, { "athlete": { "name": "Joe Doe", "age": 23 } } ] } } JS code

async function getAthletes() {

    const getPlayers = document.getElementById( getPlayers )

    await fetch( athlete.json , {
        method:  GET 
    })
    .then((response) => response.json())
    .then(data => {

        const athletes = data.team.roster[0].athlete

        for(let i = 0; i < athletes.length; i++) {
            getPlayers.inner传真 += `<option value="${athletes[i].name}">${athletes[i].name}</option>`
        }
    }) 
}

传真

<select id="getPlayers" data-category="Vote" data-action="click" data-label="Select Player">
    <option value="">Select player</option>
</select>

希望在会后再照此办理。

<select id="getPlayers" data-category="pick" data-action="click" data-label="Select Player">
    <option value>Select player</option>
    <option value="John Doe">John Doe</option>
    <option value="Jane Doe">Jane Doe</option>
    <option value="Jack Doe">Jack Doe</option>
    <option value="Joe Doe">Joe Doe</option>
</select>
问题回答

仅看一下你在此做些什么:

const athletes = data.team.roster[0].athlete

u 重建一个称为运动员的变量,将其价值确定为运动员。 仅举一例不是一件事。 在这一行动中,你具体说明了阵列的指数0。 如果你想走整个阵列,就不只使用其中的一项内容。 使用整个阵列:

 const athletes = data.team.roster; 

然后,阵列中的每一个要素都一样:

  "athlete": {
    "name": "John Doe",
    "age": 20
  }
}

提及在 lo体内的价值,就是:

 athletes[i].athlete.name 




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签