やりたいこと
オブジェクトの値の上書きを実装したいです。
下記ソースでいいますと、state.dateに格納されている値の、id配下の値を上書きしたいです。
(state.data.id == event.idの値の上書き)
現状(できなかったこと)
下記方法で、deta.[event.id]配下に値を追加しようとしたところ、
値が追加されませんでした。
また、「$set」を「$push」に変更しても、値が追加されませんでした。
type State = { loaded: boolean, ids: Array<number>, data: Array<Object>, pagesLoaded: number, needsToDisplayAppliedTickets: boolean, }; EVENT_FETCH: (state: State, action: Action) => { const event = action.payload; return update(state, { data: { [event.id]: { $set: event } }, }); 【stateのデータ】 { "data": { "2251": { "id": 2251, "title": "タイトル1", "price": 1000, "address": "アドレス1", }, "2252": { "id": 2252, "title": "タイトル2", "price": 2000, "address": "アドレス2", }, } 【eventのデータ】 { "id": 2251, "title": "タイトル1", "price": 1000, "address": "アドレス1", "address_building": "アドレス1ビル", "event_date_from": "2018/12/10 14:00", "event_date_from_month": "12", "event_date_from_day": "10", "event_date_from_weekday": "月", "event_date_to": "2020/12/10 15:00", "is_not_yet_opened": false, "is_opening": true, "is_closed": false, "total_unsold_number": 497, "display_date_from": "2018/5/9 00:00", "display_date_to": "2020/5/9 00:00", "tickets": [ { "id": 141, "title": "チケットタイトル1", "text": "テスト1", "ticket_type": "fixed_amount", "price": 2000, "display_date_from": "2018-11-01T00:00:00.000+09:00", "display_date_to": "2018-12-01T00:00:00.000+09:00", "limit_totaluser": true, "limit_totaluser_num": 500, "limit_user": true, "limit_user_num": 5, "current_limit_user_num": 3, "is_not_yet_displayed": false, "is_displaying": false, "is_end": true, "is_sold": false, "lottery_flg": "lottery_off", "unsold_number": 493 }, { "id": 58, "title": "チケットタイトル2", "text": "テスト2", "ticket_type": "fixed_amount", "price": 1000, "display_date_from": "2018-05-09T00:00:00.000+09:00", "display_date_to": "2018-11-30T00:00:00.000+09:00", "limit_totaluser": true, "limit_totaluser_num": 20, "limit_user": true, "limit_user_num": 2, "current_limit_user_num": 0, "is_not_yet_displayed": false, "is_displaying": false, "is_end": true, "is_sold": false, "lottery_flg": "lottery_off", "unsold_number": 3 }, ] }
実現させたいデータの形
{ "data": { "2251": { "id": 2251, "title": "タイトル1", "price": 1000, "address": "アドレス1", "address_building": "アドレス1ビル", "event_date_from": "2018/12/10 14:00", "event_date_from_month": "12", "event_date_from_day": "10", "event_date_from_weekday": "月", "event_date_to": "2020/12/10 15:00", "is_not_yet_opened": false, "is_opening": true, "is_closed": false, "total_unsold_number": 497, "display_date_from": "2018/5/9 00:00", "display_date_to": "2020/5/9 00:00", "tickets": [ { "id": 141, "title": "チケットタイトル1", "text": "テスト1", "ticket_type": "fixed_amount", "price": 2000, "display_date_from": "2018-11-01T00:00:00.000+09:00", "display_date_to": "2018-12-01T00:00:00.000+09:00", "limit_totaluser": true, "limit_totaluser_num": 500, "limit_user": true, "limit_user_num": 5, "current_limit_user_num": 3, "is_not_yet_displayed": false, "is_displaying": false, "is_end": true, "is_sold": false, "lottery_flg": "lottery_off", "unsold_number": 493 }, { "id": 58, "title": "チケットタイトル2", "text": "テスト2", "ticket_type": "fixed_amount", "price": 1000, "display_date_from": "2018-05-09T00:00:00.000+09:00", "display_date_to": "2018-11-30T00:00:00.000+09:00", "limit_totaluser": true, "limit_totaluser_num": 20, "limit_user": true, "limit_user_num": 2, "current_limit_user_num": 0, "is_not_yet_displayed": false, "is_displaying": false, "is_end": true, "is_sold": false, "lottery_flg": "lottery_off", "unsold_number": 3 }, ] } }, "2252": { "id": 2252, "title": "タイトル2", "price": 2000, "address": "アドレス2", }, }
あなたの回答
tips
プレビュー