我对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什么也没返回...我有办法访问该值吗?
谢谢你阿拉
您需要添加protected $appends = ['win_pct'];
模型。在Laravel 5 Documentation http://laravel.com/docs/5.0/eloquent最后一段中查看Eloquent部分。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句