[英]add object to array in for loop in angularjs
我們需要將響應數據添加到數組,然后我們需要在html中顯示。我們嘗試這樣
var RequestAs = [];
for (var i = 0; i < RequestLength; i++)
{
$http({
method: "GET",
url: "http://183.82.0.221:2244/api/PostPets/GetCustomerDetails?ID=" + results.rows.item(i).PosterId + ""
}).then(function mySucces(response) {
var RequestA = response.data;
$scope.RequestAs.push(RequestA);
}, function myError(response) {
alert(response);
//console.log('ERR'+response.message);
});
}
我們試過像這樣的html
<div class="list" ng-hide="registered" ng-repeat="Reques in RequestAs">
<div class="item tabs tabs-secondary tabs-icon-left">
<a class="tab-item" href="#">
<i class="icon ion-person"></i>
{{Reques.CustName}}
</a>
</div>
<div class="item item-text-wrap">
{{Reques.Address}}
</div>
</div>
我們得到第一個循環的數據
[
{
"CustName": "Pavan",
"Address": "Hyd",
}
]
第二
[
{
"CustName": "Naveen",
"Address": "Eluru",
}
]
請引導我們。我的代碼中有什么問題。我們最近有一天被批評了。
你得到一系列客戶細節,你必須從中獲取對象,並且每個數組都有一個索引0的對象,試試這個
$scope.RequestAs.push(RequestA[0]);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.