[英]Passing the API into scope array?
我在下面看到了我的API。 我如何將其傳遞到這樣的范圍? 我試圖將JSON數據傳遞到如下所示的數組中,但僅傳遞符號。 可以實現嗎?
$scope.sellers = ["12312", "2324", "B23244", "2322en"]
[
{
"id": "59a7ef64053bfcf561d6bde0",
"symbol": "12121",
"clearingVenue": null,
"description": "testing",
"address": "6/9-13 smith St",
"startAt": null,
"endAt": null,
"city": "north",
"auctionDate": 1504137600000,
"term": "M",
"state": "Australia",
"zipCode": "2334",
"country": "Australia",
"relatedSymbols": ["foo"],
"showUser": true
}
]
我的API代碼
this.fetchContracts = function () {
var date = new Date().toISOString();
$http.get('/api/contracts', {params: {auctionDate: date}})
.success(function (result) {
result && result.length && ($scope.contracts = result);
});
};
因此,如果您只想獲取符號數組,則可以執行以下操作:
$http.get('/api/contracts', {
params: {
auctionDate: date
}
})
.success(function (result) {
result.map(function(v) {
$scope.yourarray.push(v.symbol)
})
});
說明:
從API獲得結果數組后,我們將對其進行迭代。 API的結果是一個對象數組。 因此我們從每個獲取的對象中獲取“符號”的值,並將其推入新數組“ yourarray”
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.