2

Trying to do a PUT request to update my API (which is Rails) and can't make it happen.

This is what I have

Building has many rooms, so I need

    let data = {
      building: {
        id: 1
        rooms: [
          {
            id: 1,
            name: Vodkin
          },
          {
            id: 2,
            name: Petrov
          }
        ]
      }

I need

    building => {id => 1, rooms => [{id => 1, name => Vodkin}, {id => 2, name => Petrov}]}

It does not give me nested object with arrays.

How do I do this in JSX syntax?

r007
  • 305
  • 1
  • 2
  • 17
evgeny
  • 1,039
  • 1
  • 9
  • 26
  • 1
    Possible duplicate of [ECMAScript6 arrow function that returns an object](http://stackoverflow.com/questions/28770415/ecmascript6-arrow-function-that-returns-an-object) – James Brierley Apr 27 '16 at 15:48
  • 1
    Wrap the `{}` in `()` – James Brierley Apr 27 '16 at 15:49
  • 2
    Hi James and thanks! Did you mean all braces or .. ? – evgeny Apr 27 '16 at 15:51
  • You need to wrap the entire object in parenthesis, otherwise it is interpreted as a code block. Look at the question I linked for details. – James Brierley Apr 27 '16 at 15:58
  • Why are you using arrow functions in the first place? – Aaron Beall Apr 27 '16 at 17:34
  • Hi Aaron! This is console output (i've copied from backend server). In fact I need just nested object with array as written above. – evgeny Apr 28 '16 at 11:45
  • James, does not work :( I've tried to put something else into rooms. rooms: ['123', '123] and it gives me [] as output however it is simple array.. This is primitive challenge, I just need to do whole model-model update (first model has many other models.. ) and I just need to construct it accordingly in react. – evgeny Apr 28 '16 at 11:47

1 Answers1

0

Finally, decided to split all into smaller chunks and update them separately.. I think this is the best practise for react.

evgeny
  • 1,039
  • 1
  • 9
  • 26