不久:
map.getIn(["a", "b", "c"])
是一个捷径map.get("a").get("b").get("c")
在细节:
你可能已经钻进了fromJS
陷阱之一。呼唤:
const map = Immutable.fromJS({a: {b: {c: "banana"}}});
只有关键a
,它的价值产生了Map
也是Map
只有关键b
,它的价值也是Map
只有关键c
和值banana
。
随着换句话说fromJS
进入所提供的对象的深,并为每个Object
和每个Array
在该示例的一个List
定义Map
,主叫map.getIn(["a", "b", "c"])
是怎样的一个快捷方式的到map.get("a").get("b").get("c")
但是,如果将map
定义为Map
:
const map = new Immutable.Map({a: {b: {c: "banana"}}});
它创建一个Map,只有键a
,其值为普通对象{b: {c: "banana"}}
,并且调用map.get("a").get("b").get("c")
会抛出类似于get is not a function
的东西,因为map.get("a")
将返回{b: ...}
纯文本对象。
同样的原因是为什么map.getIn(["a", "b", "c"])
不能像你所期望的那样工作。