1
我對AngularJS相當陌生,我正在使用Laravel 5和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沒有返回任何內容......有沒有辦法讓我訪問該值?
感謝, 阿糖胞苷