gpt4 book ai didi

javascript - ImmutableJS 设置不展平

转载 作者:行者123 更新时间:2023-11-30 08:33:33 27 4
gpt4 key购买 nike

我有以下代码:

Immutable.Set(['valor1', 'valor2', 'valor2', 'valor3', ['valor4', 'valor5']]).flatten().toJS();

这并没有像预期的那样工作,但返回了输入的内容。如果我将其视为列表,它会按预期工作:

   Immutable.fromJS(['valor1', 'valor2', 'valor2', 'valor3', ['valor4', 'valor5']]).flatten().toJS(); // return flattened list

flatten 函数与 Set 一起使用时有什么问题?

最佳答案

What's wrong with flatten function when using it with Set?

没有什么不妥。看来您对 Setflatten 的工作方式有错误的想法。来自docs :

Flattens only others Iterable, not Arrays or Objects.

Immutable.fromJS(...) 深度将值转换为Maps和Lists,因此内部数组被转换为Immutable.List,这就是它起作用的原因。构造函数进行深度转换,因此该集合包含一个数组(未展平)。

关于javascript - ImmutableJS 设置不展平,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34444543/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com