简体   繁体   English

计算(ImmutableJS)地图的所有项目?

[英]Counting all items of an (ImmutableJS) Map?

Counting the items contained in an object, I used to have: 计算对象中包含的项目,我曾经有:

Object.keys(state.posts).length

Now, I have changed my posts state into an immutablejs Map, like so: 现在,我将posts状态更改为一个immutablejs地图,如下所示:

Map({ "1": {title: "First Title"}, "2" : {title: "Second Title"} });

...but now I don't know how to count the items in the object anymore? ...但是现在我不知道如何计算对象中的项目了吗? I tried a few things like Object.keys(state.posts.get()).length and Object.keys(state.posts.entries()).length , but to no avail. 我尝试了一些类似Object.keys(state.posts.get()).lengthObject.keys(state.posts.entries()).length ,但是没有用。

To get the size or length of ImmutableJS Map you can do: 要获取ImmutableJS Map的大小或长度,您可以执行以下操作:

state.posts.size

This is as documented on ImmutableJS Map#size 如ImmutableJS Map#size中所述

According to docs: 根据文档:

state.posts.count()

will always return proper size. 将始终返回正确的大小。

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

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