我希望将Ionic的存储对象转换为可在离子视图中读取的数组。 我收到此错误:NgFor仅支持绑定到Iterables,如Arrays。 如何将对象转换为数组? 我必须为每个存储器将数据推送到阵列吗? 这是对象: 问候 弗兰克
答案 0 :(得分:0)
您可以使用ES6的Object.values来获取值数组:
var obj = {
"1": { prop: "xxx" },
"2": { prop: "yyy" },
"3": { prop: "zzz" }
}
var arr = Object.values(obj);
console.log(arr);
答案 1 :(得分:0)
我尝试使用approch获取存储离子对象的数组,如下所示:
this.storage.forEach((value: string, key: string, index: number) => {
//console.log(key);
console.log('value',value);
});
它返回一个对象的数组,但带有其他值! 奇怪...... 来自here
的解决方案