React JSX: rendering nested arrays of objects

后端 未结 2 1937
盖世英雄少女心
盖世英雄少女心 2020-12-22 09:21

I have a component with the following render:

相关标签:
2条回答
  • 2020-12-22 09:25

    You are not returning the JSX from your map method. Once you return the JSX you formed :

    policyLegend.map(function(policy) {
                  return (<div>
                    <h3 key={ policy.id }>{ policy.displayName }</h3>
                    {
                      policy.values.map(value => {
                        return(
                          <Form.Field key={ value.name }>
                            <label>{ value.displayName }</label>
                            <Checkbox toggle />
                          </Form.Field>
                        );
                      })
                    }
                  </div>)
                })
    

    You should get the result you're looking for

    0 讨论(0)
  • 2020-12-22 09:29

    It's because you do not return anything inside the policyLegend map. Try this:

    {
        policyLegend.map((policy) => {
            return (
                <div>
                    <h3 key={ policy.id }>{ policy.displayName }</h3>
                    {
                        policy.values.map(value => {
                            return(
                                <Form.Field key={ value.name }>
                                    <label>{ value.displayName }</label>
                                    <Checkbox toggle />
                                </Form.Field>
                            );
                        })
                    }
                </div>
            );
        })
    }
    
    0 讨论(0)
提交回复
热议问题