チームごとにhtmlページを表示するための静的なコードです。 mysqlデータベースレコードを使用して同じプロセスが必要です。どのような変更anuglarコントローラで必要とされているとAPImysqlデータベースレコードに基づいてangularjsのレコードをグループ化する方法
HTML
<ul>
<li ng-repeat="(team, players) in teamPlayers | groupBy:'team'">
{{team}}
<ul>
<li ng-repeat="player in players">
{{player.name}}
</li>
</ul>
</li>
</ul>
コントローラ
app.controller('homeCtrl', function($scope) {
var teamAlpha = {name: 'team alpha'};
var teamBeta = {name: 'team beta'};
var teamGamma = {name: 'team gamma'};
$scope.teamPlayers = [{name: 'Gene', team: teamAlpha},
{name: 'George', team: teamBeta},
{name: 'Steve', team: teamGamma},
{name: 'Paula', team: teamBeta},
{name: 'Scruath of the 5th sector', team: teamGamma}];
});
PHPのコード
$select=" select name, team from player where 1";
$result=$con->query($select)or die(mysqli_error());
$num=$result->num_rows;
if($num > 0)
{
$arr = array();
while($row=$result->fetch_array())
{
$arr[]=array('name'=>$row['name'],
'team'=>$row['team'],
);
}
}
$outputArr = array();
$outputArr['Player'] = $arr;
header("Content-type: application/json");
echo json_encode($outputArr);
チームのプレーヤーまたはチームのプレーヤーを返す既存のバックエンドサービスがありますか? –
@AbbéRésinaローカルサーバーにバックエンドがあります。 –