gpt4 book ai didi

javascript - 如何在 reactjs 中的数组数据中排列数组?

转载 作者:行者123 更新时间:2023-11-30 14:08:19 25 4
gpt4 key购买 nike

我在里面有一个数组,在里面有一些多个数组,我试图在数组中排列那个数组,但我不知道哪里出了问题?那么如何正确设置数组内部数组呢?以下 arrayData 可用。

const arrayData = [
form_id: 1,
countTotal: 100,
formName: 'Application Form',
questions: [
0: [
questionName: 'what is your name ?',
note: 'give firstname middlename and lastname also..',
required: true,
answer: 'my name is John dao',
sequence: 0,
questionType: 'long text',
options: [],
]
1: [
questionName: 'select your gender ?',
note: '',
required: true,
answer: 'Male',
sequence: 1,
questionType: 'Single Selector',
options: [
0: {
option_id: 1,
value: 'Male',
sequence: 0,
is_selected: true,
},
1: {
option_id: 2,
value: 'female',
sequence: 1,
is_selected: false,
},
2: {
option_id: 3,
value: 'Other',
sequence: 2,
is_selected: false,
},
],
]
]
]

最佳答案

应该是这样的:

const arrayData = [
form_id : 1,
countTotal: 100,
formName: 'Application Form',
questions: [
[
questionName => 'what is your name ?',
note => 'give firstname middlename and lastname also..',
required => true,
answer => 'my name is khan, but i am not terrorist',
sequence => 0,
questionType => 'long text',
options => [],
],
[
questionName => 'select your gender ?',
note => '',
required => true,
answer => 'Male',
sequence => 1,
questionType => 'Single Selector',
options => [
{ option_id: 1,
value: 'Male',
sequence: 0,
is_selected: true,
},
{ option_id: 2,
value: 'female',
sequence: 1,
is_selected: false,
},
{ option_id: 3,
value: 'Other',
sequence: 2,
is_selected: false,
},
],
]
]
]

您不应该手动提供索引,因为它已经自动注册了。

array = ['data index 0','data index 1','data index 2'];

此外,您还可以使用此方法注册自己的索引:

array = [index1 => 'data index 1', index2 => 'data index 2'];

关于javascript - 如何在 reactjs 中的数组数据中排列数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54943908/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com