2016-09-16 35 views
1
を返すために

状態は次のようにあります:私はreview.snippetsを設定したい場合は、[1] .flag = trueを今すぐどのようにReduxの減速のオブジェクト配列状態

review: { 
    "amount": 217, 
    "snippets": [ 
     { 
     "id": 0, 
     "flag": false 
     }, 
     { 
     "id": 1, 
     "flag": false 
     }, 
     ... 
    ] 
    } 

、何をで書くべき減速機?たとえば :あなたはあなたの店の別の部分にcombineReducersを使用していない場合

case SET_FLAG: return { 
    ...state, 
    review: { 
     ...state.review, 
     snippets: { 
     ...state.review.snippets, 
     // don't know how to write here to express array 
     } 
    }, 
}; 

答えて

0

あなたが似てあなたの減速機ケースを保つが、スニペット配列

// grab your snippets 
const snippets = state.review.snippets 

// create a copy 
const snippetsCopy = snippets.slice() 

// replace the element with a new object with the same properties 
// and overwrite the property you want 
snippetsCopy[1] = { 
    ...snippetsCopy[1], 
    flag: true 
} 
const newSnippetsArray = Object.assign(arr, newArr) 

// in your switch case return something like this: 

return { 
    ...state, 
    review: { 
     ...state.review, 
     snippets: newSnippetsArray 
    }, 
}; 
に、このような操作を行うことができます
関連する問題