2017-05-10 5 views
0

은 그럼 내가 REST API 호출을 말이 형식으로 JSON을받을 수 있도록지도에 새 속성을 추가로 불변으로 만들어 내 감속기의Immutable.Js -

{ 
    "plan": { 
     "createdDate": "05/04/2017", 
     "location": { 
      "city": null 
      "state": null 
     } 
     "family": null 
    } 
} 

그리고 내 JSON을 그래서 : 길을 따라

Immutable.Map(Immutable.fromJS(action.json)) 

, 그것은 family에서 속성을 추가 할 수 있습니다?

{ 
    "plan": { 
     "createdDate": "05/04/2017", 
     "location": { 
      "city": null 
      "state": null 
     } 
     "family": { 
      "father": "Homer", 
      "mother": "Marge", 
      "son": "Bartholomew" 
     } 
    } 
} 

을 아니면 처음부터 family에서 이러한 속성을 가지고 처음으로 초기화해야합니까 : 나는 서버에 양식을 제출하고 때 예를 들어

, 이상적으로 나는 이런 식으로 뭔가를 보내려고?

기록을 위해

답변

0

, 당신은

const m = Immutable.Map(Immutable.fromJS(action.json)) 

그러나

const m = Immutable.fromJS(action.json) 

이 작업을 수행 할 필요가 없습니다 그리고

당신은 다만 할 수 있습니다

const n = m.setIn(['plan', 'family'], /* your family object */) 

여기 :

const n = m.setIn(['plan', 'family'], Immutable.Map({ father: 'Homer', mother: 'Marge', son: 'Bartholomew' }))