Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

`javascript` Can we use map function again using map function argument value?

console.log(materialIngredientDetail)

[
    {
        "content": "asd",
        "type": "one",
        "certificationNum": "1123-522",
        "functionalList": [
            {
                "id": 132,
                "valueUnit": "mg",
                "functionalDisplayTxt": "hi"
            },
            {
                "id": 133,
                "valueUnit": "mg",
                "functionalDisplayTxt": "ww"
            },
            {
                "id": 134,
                "valueUnit": "mg",
                "functionalDisplayTxt": "ee"
            },
            {
                "id": 135,
                "valueUnit": "mg",
                "functionalDisplayTxt": "ff"
            }
        ]
    },
    {
        "content": "qwe",
        "type": "two",
        "certificationNum": "421-123",
        "functionalList": [
            {
                "id": 129,
                "valueUnit": "mg",
                "functionalDisplayTxt": "aa"
            },
            {
                "id": 130,
                "valueUnit": "mg",
                "functionalDisplayTxt": "bb"
            }
        ]
    }
]

I am trying to display this in JSX syntax using the map function.

  <div>
        {materialIngredientDetail.map((Fields, index) => (
          <Fragment key={`${Fields}~${index}`}>
            <Card title={`${Fields.type} - ${Fields.certificationNum} - ${Fields.content}`}>
            {Fields.functionalList.map((value, key) => {
                <> 
                <p>{value.id}</p>
                <p>{value.functionalDisplayTxt}</p>
                <p>123</p>
                <p>{value.valueUnit}</p>
                </>
            })}
            </Card>
          </Fragment>
        ))}
      </div>

The problem is that the output is normal and there are no errors, but the data values ​​are not output in the code part here.

    {Fields.functionalList.map((value, key) => {
                <>
                <p>{value.id}</p>
                <p>{value.functionalDisplayTxt}</p>
                <p>123</p>
                <p>{value.valueUnit}</p>
                </>
            })}

Is it not possible to use the map function again using the InputFields argument value?
How should I modify the code?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You are not returning the jsx from second map. try below listed code

{Fields.functionalList.map((value, key) => {
                        return (<>
                        <p>{value.functionalDisplayTxt}</p>
                        <p>123</p>
                        <p>{value.valueUnit}</p>
                        </>)
                    })}

OR

{Fields.functionalList.map((value, key) => (<>
                        <p>{value.functionalDisplayTxt}</p>
                        <p>123</p>
                        <p>{value.valueUnit}</p>
                        </>)
                    )}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading