将列表添加到 Immutable.js 中的列表的最佳方式是什么? ?
concat
方法有效,但另一种方法无效。
const a = fromJS([
{
comment: 'aaaa',
who: 'a1',
buttonInfo: ['a', 'b', 'c'],
},
{
comment: 'bb',
who: 'a2',
buttonInfo: ['a', 'b', 'c'],
},
]);
const b = fromJS([
{
comment: 'ccc',
who: 'c1',
buttonInfo: ['a', 'b'],
},
{
comment: 'ddd',
who: 'd2',
buttonInfo: ['a''],
},
]);
这正在工作:
a.concat(b)
但这不起作用:
[...a ,...b]
// or
b.map(v => {
a.push(v);
})
最佳答案
您可以使用 concat 方法,如文档中所述:
const list1 = List([ 1, 2, 3 ]);
const list2 = List([ 4, 5, 6 ]);
const array = [ 7, 8, 9 ];
const list3 = list1.concat(list2, array);
// List [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
关于javascript - 如何在 Immutable.js 中添加列表到列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53260616/