将ORDS连接到Angular

问题描述

我有要从ORDS服务器检索的json格式数据,它看起来像这样:

{“ items”:[{“ cust_code”:“ C00013”,“ cust_name”:“ Holmes”,“ cust_city”:“伦敦 “,” working_area“:”伦敦“,” cust_country“:”英国“,”等级“:2,” opening_amt“:6000,” receive_amt“:5000,” payment_amt“:7000,” outstanding_amt“:4000,” phone_no “:” BBBBBBB“,” agent_code“:” A003 “},{” cust_code“:” C00001“,” cust_name“:” Micheal“,” cust_city“:”纽约
“,” working_area“:”新 York”,“ cust_country”:“ USA”,“ grade”:2,“ opening_amt”:3000,“ receive_amt”:5000,“ payment_amt”:2000,“ outstanding_amt”:6000,“ phone_no”:“ CCCCCCC”,“ agent_code“:” A008 “},{” cust_code“:” C00020“,” cust_name“:” Albert“,” cust_city“:”纽约
“,” working_area“:”新 York”,“ cust_country”:“ USA”,“ grade”:3,“ opening_amt”:5000,“ receive_amt”:7000,“ payment_amt”:6000,“ outstanding_amt”:6000,“ phone_no”:“ BBBBSBB”,“ agent_code“:” A008 “},{” cust_code“:” C00025“,” cust_name“:” ravindran“,” cust_city“:”班加罗尔 “,” working_area“:”班加罗尔“,” cust_country“:”印度“,”等级“:2,” opening_amt“:5000,” receive_amt“:7000,” payment_amt“:4000,” outstanding_amt“:8000,” phone_no “:” AVAVAVA“,” agent_code“:” A011 “},{” cust_code“:” C00015“,” cust_name“:” Stuart“,” cust_city“:”伦敦
“,” working_area“:”伦敦“,” cust_country“:”英国“,”等级“:1,” opening_amt“:6000,” receive_amt“:8000,” payment_amt“:3000,” outstanding_amt“:11000,” phone_no “:” GFSGERS“,” agent_code“:” A003 “}],” hasMore“:false,” limit“:25,” offset“:0,” count“:5,” links“:[{” rel“:” self“,” href“:” http:/ / localhost:9000 / ords / demo / customers / getAll /“},{” rel“:” describeby“,” href“:” http:// localhost:9000 / ords / demo / Metadata-catalog / customers / getAll / “},{” rel“:” first“,” href“:” http:// localhost:9000 / ords / demo / customers / getAll /“}]}

所以我想知道是否有一种方法可以分解项目部分,并使用anguler将其放入表格中。

我尝试在ts文件中使用这种方式:

http.get('http://localhost:9000/ords/demo/customers/getAll/')
    .subscribe(data => this.items = data);

但是我一直收到此错误

错误:尝试区分'[object Object]'时出错。仅允许数组和可迭代对象

解决方法

您想要的数组位于items属性中,因此您必须这样做

http.get('http://localhost:9000/ords/demo/customers/getAll/')
    .subscribe(data => this.items = data.items);