1
我怎樣才能找到一個嵌套的JSON對象並用AngularJS輸出?我已經搞了很長一段時間了,但我似乎無法做到。希望你們能幫助我!如何使用angularjs查找嵌套的json對象?
HTML:
<div id="ng-app" ng-controller="AnalyticsCtrl">
<div ng-repeat="post in posts">
<span>{{post.title}}</span>
<span>{{post.counter}}</span>
</div>
</div>
JSON: 我試圖獲取文章標題,計數器
{
"status" : "success",
"data" :
{
"activeVisitors" : "148",
"posts" :
[
{
"id" : 1,
"title" : "Bla blabla blablabl bla blablaba",
"counter" : "20"
},
{
"id" : 2,
"title" : "Blie bla blup wflup flel del",
"counter" : "18"
},
{
"id" : 3,
"title" : "Flel djep flep tro fro klel",
"counter" : "14"
}
]
}
}
Ctrl鍵:
'use strict';
var myApp = angular.module('myApp', []);
myApp.controller('AnalyticsCtrl', ['$scope', '$http', function($scope,$http) {
$http({method:'POST', url: 'jsonData.php', headers: {}})
.success(function(data) {
$scope.posts = data;
});
}]);
在'帖子在帖子中'使用'YourVar.data.posts'中的帖子 – Satpal
顯示AnalyticsCtrl控制器 –
添加控制器 –