简体   繁体   English

NgFor 只支持绑定 Ionic3 中的可迭代对象,例如数组

[英]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.

相关问题 angular 2 NgFor仅支持绑定到可迭代对象,例如数组 - angular 2 NgFor only supports binding to Iterables such as Arrays 错误:“对象”类型的“[对象对象]”。 NgFor 仅支持绑定到 Iterables,例如 Arrays。 - 离子项目 - Error: '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays. - Ionic Project Angular2:NgFor仅支持绑定到可迭代对象,例如数组 - Angular2: NgFor only supports binding to Iterables such as Arrays Angular-选择时出错-NgFor仅支持绑定到数组等Iterable - Angular - Error on Select - NgFor only supports binding to Iterables such as Arrays Angular“ NgFor仅支持绑定到可迭代对象,例如数组”错误 - Angular “NgFor only supports binding to Iterables such as Arrays” Error Angular 9 应用“NgFor only support binding to Iterables such as Arrays”报错 - Angular 9 application “NgFor only supports binding to Iterables such as Arrays” error 如何消除此错误 NgFor 仅支持绑定到 Iterables,例如 Arrays - how to remove this error NgFor only supports binding to Iterables such as Arrays 找不到支持 object 类型为“object”的“[object Object]”的差异。 NgFor 只支持绑定到 Iterables,比如 Arrays - Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables, such as Arrays Angular 7 找不到类型为“object”的不同支持对象“[object Object]”。 NgFor 只支持绑定到 Iterables,比如 Arrays - Angular 7 Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays 错误找不到类型为“对象”的其他支持对象“ [对象对象]”。 NgFor仅支持绑定到可迭代对象,例如数组 - ERROR Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM