2015-05-10 74 views
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没有返回任何内容......有没有办法让我访问该值?

感谢, 阿糖胞苷

回答