当用户点击添加按钮时,我试图将变量添加到从API接收的现有JSON数据中。当我尝试我得到这个错误。

Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays


数据被分配给名为pageList的变量
下面是如何从服务器返回数据

数据

[{"id":5,"referenceId":1189,"firstName":"Dan","lastName":"Daniels","orders":[{"id":109,"meals":[{"id":47,"name":"Fried Rice","description":"This is a  very sweet meal","image":"","mealType":"LUNCH","unitPrice":-20,"status":"ENABLED"}],"serveDate":"2019-07-11 00:00:00"}]}]


功能

AddtoList() {
       const meals =  {'id': '0','name': 'New Food', 'unitPrice':'5'}
       this.pageList.push({
                  'firstName': 'Jackson',
                  'lastName': 'Jack',
                  orders: {meals: meals}
                })
}

最佳答案

我认为orders应该是一个数组。请看如下:

this.pageList.push({
  'firstName': 'Jackson',
   'lastName': 'Jack',
   orders: [{meals: meals}]
})

09-20 22:00