我有一个API响应数据,如下所示,我正在尝试提取我需要的联系人。
$scope.data = Object { ACCOUNT: "{"ACNO":"AC052","NAME":"madavi",…}",
CONTACTS: Array[1], RETURN: "TRUE" }
从json中提取CONTACTS之后我得到了
Array [ "{"CONTACTNAME":"Mr. sdhar","CONTA…"}",
"{"CONTACTNAME":"Ms. uma","CONTACTPH…"}" ]
我正在尝试这样
$scope.contactdetails = data.CONTACTS;
<div ng-repeat="contacts in contactdetails">
<a> {{ contact.CONTACTNAME }} </a>
<a> {{ contact.CONTACTEMAIL }} </a>
<a> {{ contact.CONTACTPHONE }} </a>
<br>
</div>
如何在ng-repeat中获取值?
答案 0 :(得分:1)
数组中的每个元素似乎都是字符串形式,因此在分配之后运行JSON.parse:
$scope.contactdetails = data.CONTACTS;
for(var x = 0; x < $scope.contactdetails.length; x++){
$scope.contactdetails[x] = JSON.parse($scope.contactdetails[x]);
}