javascript - 如何在 HTML View 中使用 AngularJs 浏览列表?

标签 javascript angularjs

在 Ionic 框架中使用 AngularJS。 在前端,$scope 包含

  1. 包含运动列表的 User 对象:

    $scope.user = { sports: { "running": true, "football": true } }

  2. 名为“matches”的列表,其中包含用户列表,每个用户都有运动项目。示例:

    matches = { userA: {..., sports: {"running": true, "football": true} }, userB: {..., sports: {"rugby": true, "football": true} }

在y前端:

<ion-item class="item-thumbnail-left" ng-repeat="match in matches track by match.user.uid">
  <img>
  <span>{{match.user.firstname}} {{match.user.lastname}}</span>
  <h3>{{match.user.position}} - {{match.user.lob}}</h3>
  <h3>@{{match.company}}</h3>
  <h4>{{match.score}} sport(s): </h4>
  <h4 ng-repeat="sport in match.user.sports track by sport.id" style="float: left;">
    {{sport.name}}
  </h4>
</ion-item>

我想突出显示 $scope.user 与每个 $scope.matches.user 共有的运动(例如,将运动着色为红色)。

您建议我如何执行此操作?

谢谢

最佳答案

一旦您要操作 DOM,创建一个指令看起来是正确的选择。您可以创建一个接收 $scope.user 和 $scope.matches.user 的指令,并将突出显示应用于公共(public)区域。

您还可以使用 ng-class 指令根据表达式突出显示。

关于javascript - 如何在 HTML View 中使用 AngularJs 浏览列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40996031/

相关文章:

javascript - angularjs-在同一 Controller 的函数之间传递数据

javascript - 对于 javascript 中的循环速度性能

javascript - angularjs 模块和 Controller 不工作

javascript - AngularJS 使用的架构设计模式

javascript - 如何在更改之前捕获输入 radio 值?

javascript - Bootstrap多级下拉幻灯片效果?

javascript - 我可以在前端 Javascript 中运行 SQL 查询吗?

javascript - Bootstrap 4下拉菜单悬停与Jquery

javascript - 多步 Angular ng-repeat 可提高性能

javascript - ng 重复 json 解析显示空字符串