我正在使用角度移动Ui框架工作。我从控制器中的URL获取数据。但现在我想成功获取特定数据。我将显示我的代码片段提示。从JavaScript中获取成功的数据(Ajax)角度js
HTML:
<div class="jumbtron scrollable-content text-center bg-color">
<div class="row">
<div class="bgImage">
</div>
<div class="btn-group img-responsive" ng-controller="MyControllerCity">
<div ng-repeat="prdct in cityProduct">
<a href="#/category-prduct" style="color:#763428; font-weight:bold;">
<img src="{{prdct.categoryImage}}">
</a>
</div>
</div>
</div>
</div>
控制器:
.controller('MyControllerCity',function($scope, $http){
$http({
method:'get',
url:'http://192.168.0.3/sf/app/city-home/1',
headers: {'Content-Type': 'application/json'},
}).success(function(data, status,headers, config) {
$scope.cityProduct = data;
console.log("aaaaaaa" + cityProduct.categoryId);
}).error(function(data, status, headers ,config) {
})
})
console.log("aaaaaaa" + cityProduct.categoryId);
但在控制台CATEGORYID不显示。
这里是JSON响应:
[{
"categoryImage": "https://www.winni.in/assets/img/app/city-home/cake.jpg",
"categoryName": "cakes",
"categoryId": 4
}, {
"categoryImage": "https://www.winni.in/assets/img/app/city-home/flowers.jpg",
"categoryName": "flowers-and-bouquets",
"categoryId": 12
}, {
"categoryImage": "https://www.winni.in/assets/img/app/city-home/chocolates.jpg",
"categoryName": "chocolates-for-all",
"categoryId": 63
}, {
"categoryImage": "https://www.winni.in/assets/img/app/city-home/mugs.jpg",
"categoryName": "Mugs",
"categoryId": 34
}, {
"categoryImage": "https://www.winni.in/assets/img/app/city-home/figurines.jpg",
"categoryName": "figurines",
"categoryId": 84
}, {
"categoryImage": "https://www.winni.in/assets/img/app/city-home/giftframes.jpg",
"categoryName": "gift-and-photo-frames",
"categoryId": 106
}, {
"categoryImage": "https://www.winni.in/assets/img/app/city-home/greetingcards.jpg",
"categoryName": "greeting-cards",
"categoryId": 103
}, {
"categoryImage": "https://www.winni.in/assets/img/app/city-home/handicrafts.jpg",
"categoryName": "handicrafts",
"categoryId": 44
}, {
"categoryImage": "https://www.winni.in/assets/img/app/city-home/penstands.jpg",
"categoryName": "pen-stands",
"categoryId": 142
}, {
"categoryImage": "https://www.winni.in/assets/img/app/city-home/combos.jpg",
"categoryName": "gift-combos",
"categoryId": 99
}, {
"categoryImage": "https://www.winni.in/assets/img/app/city-home/softtoys.jpg",
"categoryName": "soft-toys",
"categoryId": 104
}, {
"categoryImage": "https://www.winni.in/assets/img/app/city-home/diecasttoys.jpg",
"categoryName": "diecast-toys",
"categoryId": 138
}, {
"categoryImage": "https://www.winni.in/assets/img/app/city-home/jewellery.jpg",
"categoryName": "jewellery",
"categoryId": 41
}, {
"categoryImage": "https://www.winni.in/assets/img/app/city-home/clocks.jpg",
"categoryName": "clocks",
"categoryId": 137
}, {
"categoryImage": "https://www.winni.in/assets/img/app/city-home/crystalgifts.jpg",
"categoryName": "crystal gifts",
"categoryId": 136
}, {
"categoryImage": "https://www.winni.in/assets/img/app/city-home/lamps.jpg",
"categoryName": "lamps",
"categoryId": 97
}, {
"categoryImage": "https://www.winni.in/assets/img/app/city-home/slambook.jpg",
"categoryName": "slambook",
"categoryId": 139
}]
我想在控制台得到的categoryId。
我用:
console.log("categoryId "+cityProduct[0].categoryId);
在此先感谢。
'$ scope.cityProduct = cityProduct' – dandavis
ISTR该'.success'已被弃用 – Alnitak