javascript - 如何检查 ng-show={{}} 表达式与值数组列表是否匹配?

标签 javascript angularjs angularjs-scope

我正在尝试检查评估具有多个对象的每个 ng-repeat 列表数组。 有办法实现这一点吗?

请查找以下代码供您引用。

    **<div ng-repeat="i in items" ng-show="items.id === arrayList[]" />

$scope.arrayList = [{"id":"1"},{"id":"2"},...]**

我需要检查 items.id 是否与任何 arraylist object.id 匹配。任何人都可以帮助我吗?

items 中的 i 来自 api 服务

最佳答案

在 Controller 中编写一些函数,例如这样。

  $scope.isMatch = function(id) {
    for(var i =0; i < arrayList.length; i ++){
       if(arrayList[i].id === id){
          return true;
       }
    }
    return false;    
  }

然后在 View 中使用它。

ng-show="isMatch(i.id)"

关于javascript - 如何检查 ng-show={{}} 表达式与值数组列表是否匹配?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37554180/

相关文章:

javascript - jQuery offset() 或 position()——当靠近另一个元素时改变一个元素的属性

javascript - 在 CSS/Javascript 中启用 Chrome 标志的方法?

javascript - 如何将 Angular 图表与我的信息结合使用?

angularjs - 在组件 Angular 1.5 之间共享变量

javascript - 如何将变量从指令 (ngModel) 传递到指令外部的 html 中

javascript - jQuery 合并数据属性

javascript - Handsontable:关闭自动调整行的大小(如何设置固定高度?)

angularjs - 如何向 AngularJS 表单添加自定义验证?

javascript - 视频JS : mp4 is not working when dynamically changing the video url

javascript - AngularJS - 根据当前路径更改 href 属性