[英]Set an object to Immutable Map of key value (value is an array or list) in JavaScript
I have an object (myObj) which I want to set it to an Immutable Map that has key value shape and value is a list or an array. 我有一个对象(myObj),我想将其设置为具有键值形状且值是列表或数组的不可变映射。
const myObj = {
"a": 1,
"b": 2,
};
now I want to set this object into: 现在我想将此对象设置为:
const x = Immutable.Map({
"content": []
})
how can I get the blow result? 如何获得打击效果?
{"content": [
{
"a": 1,
"b": 2,
}
]
}
I have already tried : myObj = myObj.set("content", x) but this would not make the content value as an array. 我已经尝试过:myObj = myObj.set(“ content”,x),但这不会使content值成为数组。
Map
expects [[K, V]]
structure for adding values, also myObj.set("content", x)
is right as myObj
is not Map
it's just simple object Map
期望[[K, V]]
结构用于添加值, myObj.set("content", x)
也是正确的,因为myObj
不是Map
它只是简单的对象
const myObj = { "a": 1, "b": 2, }; const x = Immutable.Map([["content",[myObj]]]) console.log(x)
<script src="https://cdnjs.cloudflare.com/ajax/libs/immutable/3.8.2/immutable.js"></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.