[英]NgFor only supports binding to Iterables such as Arrays in Ionic3
I wish to convert an Ionic's storage object to an array to be readable in a ion view.我希望将 Ionic 的存储对象转换为一个数组,以便在离子视图中可读。 I get this error : NgFor only supports binding to Iterables such as Arrays.我收到此错误:NgFor 仅支持绑定到可迭代对象,例如数组。 How to convert an object to an array ?如何将对象转换为数组? Do i have to forEach storage the push the data to an array ?我是否必须为每个存储将数据推送到数组? This is the object :这是对象: Regards Frank问候弗兰克
You can use ES6's Object.values to get an array of values:您可以使用 ES6 的 Object.values 来获取值数组:
var obj = { "1": { prop: "xxx" }, "2": { prop: "yyy" }, "3": { prop: "zzz" } } var arr = Object.values(obj); console.log(arr);
I try an approch to get an array of the storage ionic object like this:我尝试使用一种方法来获取这样的存储离子对象数组:
this.storage.forEach((value: string, key: string, index: number) => {
//console.log(key);
console.log('value',value);
});
It returns an array of the object but with additional values !它返回一个对象数组,但带有附加值! Strange ..... Solution from here奇怪..... 来自这里的解决方案
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.