【发布时间】:2016-09-22 07:46:30
【问题描述】:
我有一个包含数组的 json 文件:
{
"people": [
{"number":"1", "name":"Gary", "surname":"Peterson", "age":"25"},
{"number":"2", "name":"Andy", "surname":"Smith", "age":"26"},
{"number":"3", "name":"Michael", "surname":"Johnson", "age":"28"}
]
}
我只想将第一个对象(人员记录)返回到我的应用程序。 当我在 AngularJS 中调用 http 服务并传递参数时,如下所示:
angular.module('mod', [])
.controller('ctrl', function($scope, $http){
$scope.serviceMethod = function(){
$http.get("url to database.json", {params: {number: 1}})
.then(function Succes(response) {$scope.person = response.data.people;});};
});
它返回所有三个对象。我在控制台(状态 200)中的控制台中没有看到任何错误,并且参数 IS 已传递(它构建了这个 url:http://urltowebsite.com/database.json?number=1)。
我在这里错过了什么?
【问题讨论】:
-
Angular 怎么知道它应该过滤
number属性?? -
据我了解,这是服务器端任务,在 angular 内无事可做,或者您可以分配返回的 JSON 的第一个元素,例如
$scope.person = response.data.people[0]
标签: javascript angularjs json http