2

I'm new to Material UI and everything in the examples is static. Is there something to see for a JSON example?

5
  • replace that static part with a loop on json and create the menu elements dynamically, like this: [values here].map(el => <Menu />) Commented May 13, 2018 at 13:07
  • Thanks. this is helpful. I'm still new to it..do you have some more detailed example? Commented May 13, 2018 at 15:43
  • can you post the json from which you want to create menu items? Commented May 13, 2018 at 15:46
  • {"ResponseMetadata": {"RequestId": "6220D8E", "HostId": "6IrP0tqhAIShLt2zsCode": 200, "HTTPHeaders": {"x-amz-id-2": "6IrP0tqhx/nDOH0p4=", "x-amz-request-id": "62AC918E", "date": "Sun, 13 May 2018 17:19:44 GMT", "content-type": "application/xml", "transfer-encoding": "chunked", "server": "AmazonS3"}, "RetryAttempts": 0}, "Buckets": [{"Name": "elasticb-east-1-6532860766", "CreationDate": "2014-09-01T16:58:41Z"}, {"Name": "elasticbeanstalk-860766", "CreationDate": "2015-10-06T00:24:57Z"}, {"Name": "elasticbeansta", "CreationDate": "2015-10-02T17:37:19Z"}], "Owner": {"DisplayName": "", "ID": "b4bf Commented May 13, 2018 at 17:21
  • Just buckets: name Commented May 13, 2018 at 18:14

1 Answer 1

1

Write it like this:

"Buckets": [
    {"Name": "elasticb-east-1-6532860766", "CreationDate": "2014-09-01T16:58:41Z"},
    {"Name": "elasticbeanstalk-860766", "CreationDate": "2015-10-06T00:24:57Z"},
    {"Name": "elasticbeansta", "CreationDate": "2015-10-02T17:37:19Z"}
]

<Menu>
    {
        this.state.Buckets.map((el,i) => (<MenuItem key={i} primaryText={el.Name} />))
    }
</Menu>

Assuming you will store the bucket values in the state variable.

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you. I will try it and let you know.
How does react know to make this iteration in HTML?
we don't write html with react, its jsx :), there we can write js in {}, i will suggest to check doc first, you will get answer of all your doubts. Doc
let me know if you have any doubt after that :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.