将不可变地图中的数据投影到不同的形状
Project data out of an immutable map to a different shape
我有一个 Map
的不可变对象,其结构如下:
id1: {
someField: 'anyvalue',
description: 'description1'
},
id2: {
someField: 'anotherValue`,
description: 'description2'
}
我想投影 List
的描述而不求助于 toJS()
:
[ 'description1', 'description2' ]
我该怎么做?
const data = new Immutable.Map({id1: {
someField: 'anyvalue',
description: 'description1'
},
id2: {
someField: 'anotherValue',
description: 'description2'
}});
const out = data.valueSeq().map(v => v.description).toList();
console.log(out)
<script src="https://cdnjs.cloudflare.com/ajax/libs/immutable/3.8.2/immutable.js"></script>
我有一个 Map
的不可变对象,其结构如下:
id1: {
someField: 'anyvalue',
description: 'description1'
},
id2: {
someField: 'anotherValue`,
description: 'description2'
}
我想投影 List
的描述而不求助于 toJS()
:
[ 'description1', 'description2' ]
我该怎么做?
const data = new Immutable.Map({id1: {
someField: 'anyvalue',
description: 'description1'
},
id2: {
someField: 'anotherValue',
description: 'description2'
}});
const out = data.valueSeq().map(v => v.description).toList();
console.log(out)
<script src="https://cdnjs.cloudflare.com/ajax/libs/immutable/3.8.2/immutable.js"></script>