react.js - TypeScript使用immutability-helper设置深层嵌套在数组里的对象属性

风影

2017-12-30T06:27:54Z||2017-12-30T06:27:54Z

import * as update from 'immutability-helper';

const state1 = {root: [{a: 1}, {b: 2}]};
// 把{b: 2} 修改成 {b: 100}
const state2 = update(state1, {root: {[1]: {b: {$set: 100}}}});
console.log(state2);

输出:

{ root: [ { a: 1 }, { b: 100 } ] }