我的网站上有一个JSON对象:
{ "ID":"102”,
"role":{“subscriber”:true},
"first_name”:”Test 3”,
"last_name”:”Test 4”,
"custom_fields":{ “job_title”:”testing”},
}
和AngularJS来管理动态内容,但它似乎并没有起作用:
var app = angular.module('myApp', []);
function PeopleCtrl($scope, $http) {
$scope.people = [];
$scope.loadPeople = function () {
var httpRequest = $http({
method: 'POST',
url: '/echo/json/',
data: mockDataForThisTest
}).success(function (data, status) {
$scope.people = data;
});
};
}
这是JSFiddle。
有人可以帮我显示数据吗?
答案 0 :(得分:1)
您的JSON存在许多问题,我已经解决了这些问题。
那里有不同类型的报价。我用"
替换了它们。
现在看起来像这样:
[{
"ID": "100",
"role": {
"subscriber": true
},
"first_name": "Test",
"last_name": "Test2",
"custom_fields": {
"job_title": "subscriber"
},
}, {
"ID": "102",
"role": {
"subscriber": true
},
"first_name": "Test 3",
"last_name": "Test 4",
"custom_fields": {
"job_title": "testing"
},
}]
此外,您未在视图中正确引用模型字段。
以下是更新的工作小提琴:http://jsfiddle.net/kmmmv83y/1/
答案 1 :(得分:1)
@qqruza让您的jsfiddle.net/1zuteco7中的回调正常运行,将网址更改为:
http://test.eventident.com/api/last_posts/siteid=&callpage=1&perpage=10&callback=JSON_CALLBACK
最后请注意JSON_CALLBACK
。您的应用程序的其余部分仍然无法正常工作,因为您没有从repeat指令中返回的数据中选择正确的绑定。在成功函数中尝试console.log(data)
,点击返回的对象并转到正确的路径。
答案 2 :(得分:0)
你在最后一个属性的末尾有一个逗号,通常会把所有内容都输出错误,下面的JSON应该可以工作:
{ "ID":"102”,
"role":{“subscriber”:true},
"first_name”:”Test 3”,
"last_name”:”Test 4”,
"custom_fields":{ “job_title”:”testing”}
}