Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
84 views
in Technique[技术] by (71.8m points)

javascript - How to display value using Object Key and value in reactjs?

I am new to ReactJS. I used context API to get the data. In my one of the states, I have Object inside Objects.

For Example:-

homeTeamClone: {
  "3a21b0a-1223-46-5abe-67b653be5704": {"id":"3a21b0a-1223-46-5abe-67b653be5704","memberName":"Adam"},
  "3a21b0a-1223-46-5abe-67b653be5705": {"id":"3a21b0a-1223-46-5abe-67b653be5705","memberName":"Chris"},
  "3a21b0a-1223-46-5abe-67b653be5706": {"id":"3a21b0a-1223-46-5abe-67b653be5706","memberName":"Martin"},
}

In another state I hold only keys for reference.

selectedMembers: {
"awayMember":"3a21b0a-1223-46-5abe-67b653be5704", "homeMember":"3a21b0a-1223-46-5abe-67b653be5705"}

Now in component when I tried to display like <div>{homeTeamClone["3a21b0a-1223-46-5abe-67b653be5704"]}</div> I'm getting an error asking I need to iterate to display the values or use array instead. But I don't want to use array.

Thanks in advance.

question from:https://stackoverflow.com/questions/65940823/how-to-display-value-using-object-key-and-value-in-reactjs

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...