我用php构建了web服务,读取数据库和echo
json。我走到路上去看结果,结果就是成功。下面是我的web服务的一个例子。
[{"id":"1","skill":"1","src":"walmart","total":"1"},{"id":"1","skill":"1","src":"target","total":"2"}]
这是我的app.js代码
(function () {
'use strict';
var app = angular.module('myApp', ['angular.filter']);
// Declare app level module which depends on views, and components
app.controller('DeveloperTable', function ($scope, $http) {
var vm = this;
// GET request example:
$http({
method: 'GET',
url: '../_includes/web_service_person.php'
}).then(function successCallback(data) {
vm.developer = data;
}, function errorCallback(data) {
console.log(":(");
});
});
})();
这是我的index.html
<div ng-controller="DeveloperTable">
<h4>Developer Assesment</h4>
<table class="table">
<tr>
<th>pid</th>
<th ng-repeat="(skill, value) in developer | groupBy: 'skill'">
{{skill}}
</th>
</tr>
有趣的是,我的控制台没有错误,但我也没有得到数据。我错过了什么?
编辑: groupBy
过滤器来自角过滤器库
ng-repeat
语法为:ng-repeat="(key, value) in myObj"
。根据你发布的json, vm.developer
是一个数组,所以skill
将被设置为数组索引。
我也不太确定groupBy: 'did'
,因为我没有看到任何did
属性在你的json对象。
试着这样写:
<th ng-repeat="data in vm.developer | groupBy: 'id'">
{{data.skill}}
</th>
几点:
你需要在你的代码中做$scope.developer = ...
, vm.developer
不在你的范围内。
除此之外,你还可以:
在浏览器中打开Firebug,进入网络选项卡,查看对web服务的HTTP请求。你可以看到它是否返回数据。如果是,像这样调试它:
查看你的HTML,添加<pre>{{developer | json}}</pre>
,我想你会看到它是空的。