ImmutableJS如何在对象内部获取值? [英] ImmutableJS how to get a value inside an object?

查看:55
本文介绍了ImmutableJS如何在对象内部获取值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个不可变的地图,我需要进入属性 name :

I have this Immutable Map and I need to get to the property name:

如果我执行 retrospective.get('users'),我可以进入用户内部,但是如果我执行 retrospective.getIn(['users','name'])不起作用...如何访问属性 name ?

If I do retrospective.get('users') I can get inside the users, but if I do retrospective.getIn(['users', 'name']) It doesn't work... how can I access to the property name?

推荐答案

它不起作用,因为 users 是一个数组.因此,您必须提供这样的索引

It does not work because users is an array. So you have to provide an index like this

retrospective.getIn(['users', 0, 'name'])

更新:

获取所有姓名

retrospective.get('users').map(user => user.get('name'))

这篇关于ImmutableJS如何在对象内部获取值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆