【发布时间】:2015-10-13 19:36:18
【问题描述】:
我有一个对象 A。
如果我JSON.stringify(A),我会得到这个结果:
{
"OrderA": [{
"orderId": "19",
"serverId": 129,
"description": "Apple",
"status": "1",
"details": ""
}]
}
现在,我想克隆它自己的元素并制作一个更大的对象,如下所示:
{
"OrderA": [{
"orderId": "19",
"serverId": 129,
"description": "Apple",
"status": "1",
"details": ""
}],
"OrderA": [{
"orderId": "19",
"serverId": 129,
"description": "Apple",
"status": "1",
"details": ""
}],
"OrderA": [{
"orderId": "19",
"serverId": 129,
"description": "Apple",
"status": "1",
"details": ""
}]
}
如何使用 lodash/underscore/ 或 jQuery 来实现?
到目前为止,我已经尝试过 jQuery.extend、lodash union,但没有奏效。
【问题讨论】:
-
那不是一个有效的对象;键应该是唯一的,例如
OrderA, OrderB, OrderC.....。 -
结构不应该是
"OrderA":[{…}, {…}, {…}]而不是"OrderA":[{…}], "OrderA":[{…}], "OrderA":[{…}]吗? -
@Xufox 哦,我只是好奇如何克隆对象的元素,结果发现我们不能有双键
标签: javascript jquery underscore.js lodash