您好,我通过以下方式将 JSON 作为对象:
{
"id": "001724",
"select": false,
"class": "product",
"Names": [
"A",
"B",
"C"
],
"available": true,
"description": "selected product",
}
我想在我的 javascript 文件中使用 Underscore.js 对 JSON 进行排序,我正在尝试将我的主要对象克隆到添加属性“名称”的“名称”对象
[{
A:[
0:{
"name":"A"
"id": "001724",
"select": false,
"class": "product",
"available": true,
"description": "selected product"
}
]
B:[
0:{
"name":"B"
"id": "001724",
"select": false,
"class": "product",
"available": true,
"description": "selected product"
}
]
C:[
0:{
"name":"C"
"id": "001724",
"select": false,
"class": "product",
"available": true,
"description": "selected product"
}
]
default:[
0:{
"name":"B"
"id": "001724",
"select": false,
"class": "product",
"available": true,
"description": "selected product"
}
]
}]
默认数组包含与“B”数组相同的内容
我正在尝试使用 underscore.js 来实现此目的
最佳答案
你试过吗:
var newObj = _(obj).clone();
关于javascript - 如何使用 underscore.js 将同一对象克隆为三个对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33683661/