0

纯 HTML:

<div class="table-tr museo_sans500">
    <div class="table-td"><a href="javascript:void(0)">fgfbgfbfg</a></div>
    <div class="table-td"><a href="javascript:void(0)">Wtrtrdgdgf</a></div>
    <div class="table-td"><a href="javascript:void(0)">Wayne Rooney</a</div>
    <div class="table-td"><a href="javascript:void(0)">fghgfhgfhgf</a></div>
</div>
<div class="table-tr museo_sans500">
    <div class="table-td"><a href="javascript:void(0)"hgfhgfhfg</a></div>
    <div class="table-td"><a href="javascript:void(0)">asdasdasdas</a></div>
    <div class="table-td"><a href="javascript:void(0)">testsfsdfs</a></div>
    <div class="table-td"><a href="javascript:void(0)">gfhgfhfghgf</a></div>
</div>

我需要使其动态化,并且我正在使用 Angular JS 和 PHP。我已经以角度获取数据$scope.teamSquad并以下列方式实现它:

<div class="table-tr museo_sans500" ng-repeat="(key,squad) in teamSquad">
     <div class="table-td"><a href="javascript:void(0)">{{squad.PlayerName}}</a></div>
</div>

但是我在添加</div><div class="table-tr museo_sans500">更多值之后遇到问题。

我已经尝试过{{key%4==0 ? '</div><div class="table-tr museo_sans500">' : ''}},但它不起作用。

我也试过,但结果是一样的。

4

1 回答 1

1

正如@entre 所说,您应该使用嵌套的 ng-repeat 来完成此任务

 <div class="table-tr museo_sans500" ng-repeat="squadChunk in teamSquad">
   <div class="table-td" ng-repeat="squad in squadChunk"><a href="javascript:void(0)">{{squad.PlayerName}}</div>
</div>

将您的数组拆分为块(大小为 4)

var _teamSquad = [
{PlayerName: 1},
{PlayerName: 2},
{PlayerName: 3},
{PlayerName: 4},
{PlayerName: 5},
{PlayerName: 6},
{PlayerName: 7},
{PlayerName: 8}
];

$scope.teamSquad = [];

var size = 4;
while (_teamSquad.length > 0)
$scope.teamSquad.push(_teamSquad.splice(0, size));

完整的解决方案

于 2015-09-14T12:31:02.890 回答