简体   繁体   English

从setIn返回地图— ImmutableJS

[英]Returning a map from setIn — ImmutableJS

I'm trying to return a nested value inside setIn, the way I'm doing it now, is that I'm accessing my value I need, but I need to map it first. 我正在尝试返回setIn内的嵌套值,即我现在正在访问的值是我要访问的值,但我需要先对其进行映射。 Immutable provides this, however, I need to use Immutable.Map().map(..) after my array. 不可变提供此功能,但是,我需要在数组后使用Immutable.Map().map(..) I get a returned value from my method, but it doesn't contain any values, of which it should. 我从我的方法中获得了一个返回的值,但是它不包含任何应该包含的值。 Anyone know another way to accomplish this? 有人知道另一种方式来实现这一目标吗? 在此处输入图片说明

You need to pass an iterable to the Immutable.Map() constructor, otherwise you are creating an empty map. 您需要将一个Iterable传递给Immutable.Map()构造函数,否则您将创建一个空映射。

It's hard to be precise without more details, but assuming that 'result' is an array of resources and you need an array of resource ids, than something like this should work. 没有更多细节很难精确,但是假设“结果”是一个资源数组,并且您需要一个资源ID数组,而不是类似的事情。

let tempStateId = newState.setIn([populateKey, 'íds'], Immutable.Map(result).map(resource => resource.id))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM