Arrays 角度为8的多维对象数组
我想将数据发送到*ngFor。我以JSON对象的形式从LocalStorage获取数据。解析对象后,我不明白如何将完整对象转换为数组?这就是目标:Arrays 角度为8的多维对象数组,arrays,json,angular,typescript,object,Arrays,Json,Angular,Typescript,Object,我想将数据发送到*ngFor。我以JSON对象的形式从LocalStorage获取数据。解析对象后,我不明白如何将完整对象转换为数组?这就是目标: { "Monti": { "name": "Visa & MasterCard", "code": "monti", "deposit": "Free", "depositProcessing": "Instant", "icon": "<img src=\"//cdn.example.com
{
"Monti": {
"name": "Visa & MasterCard",
"code": "monti",
"deposit": "Free",
"depositProcessing": "Instant",
"icon": "<img src=\"//cdn.example.com/_payicons/monti.png\"/>",
"supportWithdrawal": true,
"withdrawAllowedWithoutDeposit": false,
"depositLimits": {
"currency": "EUR",
"min": 10,
"max": 5000
}
},
"Montii": {
"name": "Visa & MasterCard",
"code": "monti",
"deposit": "Free",
"depositProcessing": "Instant",
"icon": "<img src=\"//cdn.example.com/_payicons/monti.png\"/>",
"supportWithdrawal": true,
"withdrawAllowedWithoutDeposit": false,
"depositLimits": {
"currency": "EUR",
"min": 10,
"max": 5000
}
}
}
{
“蒙蒂”:{
“名称”:“Visa&MasterCard”,
“代码”:“蒙蒂”,
“存款”:“免费”,
“存款处理”:“即时”,
“图标”:“,
“支持撤回”:对,
“取款无存款”:假,
“存款限额”:{
“货币”:“欧元”,
“min”:10,
“最大值”:5000
}
},
“蒙蒂”:{
“名称”:“Visa&MasterCard”,
“代码”:“蒙蒂”,
“存款”:“免费”,
“存款处理”:“即时”,
“图标”:“,
“支持撤回”:对,
“取款无存款”:假,
“存款限额”:{
“货币”:“欧元”,
“min”:10,
“最大值”:5000
}
}
}
您有一个包含两个其他对象的对象。我想你想要的是一个对象数组,它会像:
[
{
"name": "Visa & MasterCard",
"code": "monti",
"deposit": "Free",
"depositProcessing": "Instant",
"icon": "",
"supportWithdrawal": true,
"withdrawAllowedWithoutDeposit": false,
"depositLimits": {
"currency": "EUR",
"min": 10,
"max": 5000
}
},
{
"name": "Visa & MasterCard",
"code": "monti",
"deposit": "Free",
"depositProcessing": "Instant",
"icon": "",
"supportWithdrawal": true,
"withdrawAllowedWithoutDeposit": false,
"depositLimits": {
"currency": "EUR",
"min": 10,
"max": 5000
}
}
]
您只需在将其保存到localStorage
时修复它。如果不可能,您可以在该对象上运行“for in”循环,以从中生成数组
let arr = [];
for(let key in obj) {
arr.push(obj[key]);
}
谢谢,这很有效。但是有一个问题,为什么我不使用Obj[value]?因为你通过对象的键得到一些值,而不是通过值本身。