【发布时间】:2014-11-26 06:08:13
【问题描述】:
我试图让 Angular 显示我通过 PDO 从数据库中提取的 JSON 数据。 PDO 部分和 JSON 编码部分工作正常——控制台按预期返回数据。
但是,当使用 ng-repeat 时,divs 会显示,但 post.time 不会显示。
HTML
<html ng-app="dataVis">
. . .
<body ng-controller="GraphController as graph">
<div ng-repeat="post in graph.posts track by $index">
{{post.time}}
</div>
</body>
</html>
JSON 数据
[
{
"time": "1340",
"postId": "282301",
"likes": "2"
},
{
"time": "1300",
"postId": "285643",
"likes": "0"
}
] . . . (etc)
JS
(function () {
var app = angular.module('dataVis', []);
app.controller('GraphController', ['$http', function ($http) {
var graph = this;
graph.posts = [];
$http.get('/query-general.php').success(function (data) {
console.log(data); // returns JSON data
graph.posts = data;
});
}]);
}());
起初我没有包含track by $index,但在收到欺骗错误后我决定包含它。
我想使用 ng-repeat 在 HTML 页面中显示 JSON 数据。任何人都可以伸出援助之手来完成这项工作吗?
【问题讨论】:
-
请把所有东西都放在这里。
-
您确认HTTP请求成功返回数据了吗?
-
是的,数据返回成功。
console.log(data)返回预期的 JSON 数据
标签: javascript json angularjs angularjs-ng-repeat