ng-repeat中的单个值

时间:2018-10-15 09:16:08

标签: php angularjs json

在我的主要ng-repeat div中,我有一个仅包含一个匹配值的div,我现在尝试执行的操作导致相同的值出现在每个游戏中,因为它在主要ng重复中,我应该怎么做的

<div class="row spacing10" ng-controller="latestfeed">
  <div class="col s1 offset-s11 time" ng-repeat="latest in latestfeed">{{ latest.minute }}</div>
</div>

只获取匹配游戏的活动记录?

HTML:

  <div id="live" class="container" ng-controller="games">
    <div ng-repeat="game in games">
      <div class="card-panel">
        <div class="row spacing10">
          <div class="col s11" ng-class="{'bold': game.firstscore > game.secondscore}">{{ game.first}}</div>
          <div class="col s1 customred" ng-class="{'customgreen': game.second > game.second}">{{ game.first|| 0 }}</div>
        </div>
        <div class="row spacing10" ng-controller="latestfeed">
          <div class="col s1 offset-s11 time" ng-repeat="latest in latestfeed">{{ latest.minute }}</div>
        </div>
        <div class="row">
          <div class="col s11" ng-class="{'bold': game.second> game.first }">{{ game.second}}</div>
          <div class="col s1 customred" ng-class="{'customgreen': game.secondscore > game.firstscore }">{{ game.secondscore|| 0 }}</div>
        </div>
      </div>
    </div>
  </div>

app.js

app.controller('games', function ($scope, $http) {
  $http.get('https://www.website.com/app/?data=games').success(function (data) {
    $scope.games= data;
  });
});

app.controller('latestfeed', function ($scope, $http) {
  $http.get('https://www.website.com/app/?data=latestfeed').success(function (data) {
    $scope.latestfeed = data;
  });
});

PHP JSON查询:

games:
$sql->query('SELECT * FROM games WHERE dateofgame = :date');

latestfeed:
        $sql->query('SELECT * FROM event_items, feed, games
                     WHERE event_items.event_id = feed.event_id
                     AND feed.gamenumber = games.gamenumber
                     AND day = :date
                     ORDER BY feed.time DESC LIMIT 1');

简短的游戏查询输出:

[{"gamenumber":6160,"},{"gamenumber":6161,"}]

最新查询查询输出:

[{"event_id":4,"gamenumber":6160,"minute":40,"}]

HTML输出: 一个div包含游戏号6160,一个div包含游戏号6161,在这种情况下,分钟40仅应显示在第一个div中

1 个答案:

答案 0 :(得分:0)

ng-repeat="latest in latestfeed" ng-if="latest.gamenumber === game.gamenumber"修复了这个问题,我是Angular的新手,不知道这是有可能的