【发布时间】:2015-05-10 22:05:37
【问题描述】:
我对 AngularJS 还很陌生,我正在使用 Laravel 5 和 AngularJS 开展一个新项目。
所以基本上,我正在尝试根据一些过滤器更新排名。
这是我如何调用我的 api:
$http.post('/api/standings', {
category: $scope.current_category.id,
division: $scope.current_division.id,
gender: $scope.current_gender.slice(0,1),
season: $scope.current_season.id
}).
success(function(data, status, headers, config) {
var standings_array = [];
var stats_array = [];
angular.forEach(data, function(value,key){
standings_array[key] = value[0];
stats_array[key] = value[1];
});
$scope.standings = standings_array;
$scope.team_stats = stats_array;
});
这就是我返回数组的方式:
$teams_array[] = array($team,$stats);
return $teams_array
我的看法:
<tr ng-repeat='team in standings'>
<td><% $index+1 %></td>
<td><% team.name %></td>
<td><% team_stats[$index].games_played %></td>
<td><% team_stats[$index].points %></td>
<td><% team_stats[$index].win_pct %></td>
</tr>
一切都很好,除了 win_pct,因为它是一个模型访问器:
public function getWinPctAttribute()
{
$pct = Utils::calculatePercentage($this->points,$this->games_played*3);
$pct = number_format($pct, 2);
return $pct;
}
但是 win_pct 什么也没返回...有没有办法让我访问那个值?
谢谢, 阿拉
【问题讨论】:
标签: php angularjs eloquent laravel-5