我有如下所示的数组(5-8),如何使用react seState选择要为每个数组返回的问题(对象)的数量。
const topic = [{
questions: "The one question is here",
answer: "A",
answers: {
a: "this is option A",
b: "this is option B",
c: "this is option C",
d: "this is option D",
}
},
{
questions: "The two question is here",
answer: "A",
answers: {
a: "this is option A",
b: "this is option B",
c: "this is option C",
d: "this is option D",
}
}
]
)实际选择每个数组要返回的对象数
发布于 2018-09-02 13:30:32
我真的不知道你想要什么,但据我所知,你可以为每个问题分配一个Id
,你可以使用uuid
,例如:
const topic = [{
id:1,
questions: "The one question is here",
answer: "A",
answers: {
a: "this is option A",
b: "this is option B",
c: "this is option C",
d: "this is option D",
}
},
{
id:2,
questions: "The two question is here",
answer: "A",
answers: {
a: "this is option A",
b: "this is option B",
c: "this is option C",
d: "this is option D",
}
}
]
现在您有了每个问题的id,您可以在state中设置如下内容
state={
{id:1,count:2},
{id:2,count:3}
}
现在,您有了每个问题的id和返回的每个项目的计数。现在你可以做你想做的事了。
https://stackoverflow.com/questions/52134164
复制相似问题